jashkenas/coffee-script — Issue #1778: Add header with version number to compiled JS
Author: TrevorBurnham
Created: 2011-10-18 15:30:19+00:00
State: open

It would be nice if `.js` files compiled from CoffeeScript started with a simple comment like

// Generated by CoffeeScript 1.1.2

There would be three major advantages to this:

1. Documentation. The implicit message would be, "Do not modify this JS file directly."
1. Compiled file detection. It'd be a big help for projects like GitHub that have good reason to treat compiled JS files differently from hand-coded JS.
1. Maintainability. If a project is dormant for several months, there's a chance that the project's CoffeeScript code will no longer work as intended with the latest version of CoffeeScript. Knowing exactly which version of CoffeeScript was used for the project before would make migration a lot easier.

That last reason is, in my view, the big one. It's great that CoffeeScript has been stable for the last several months (hurray, my book isn't obsolete yet!), but it'd be nice to make some breaking changes in the future, and most CoffeeScript projects aren't documenting the version of CoffeeScript they're being compiled with.

As to the precise implementation: `CoffeeScript.compile` should accept a `header` flag, which would be set to `true` when the compiler is invoked from `command.coffee` to generate a JS file. That way, it wouldn't show up in cases like `coffee -pe "foo()"` or in environments like Try CoffeeScript. Sound good?