Make "// Generated by CoffeeScript" optional #2353

Closed
bclinkinbeard opened this Issue May 22, 2012 · 24 comments

Projects

None yet
@bclinkinbeard

It would be nice to be able to turn this off with a flag. Useful if you are working on a project that is officially "pure JS" but want to write your own code in CS.

@michaelficarra
Collaborator

You can use coffee -p input.coffee > output.js for now.

@bclinkinbeard

Yes but that is hardly a scalable solution. Is this something that would be approved if a pull request were submitted?

@michaelficarra
Collaborator

Probably not without a better reasoning. Can you go into why it's so necessary not to generate the comment?

@bclinkinbeard

The scenario I've primarily considered is one where you may be the only one on a team writing your code in CoffeeScript. While #1793 (comment) from the original issue to add the comment states that there is good reason to treat generated JS different from hand coded JS, I disagree. Why differentiate? For a project whose motto is "it's just JavaScript" that seems like an odd position to take. I also don't see why this desire would only be accommodated with the -p flag but not in a -cw scenario. IMO it should either be completely unavoidable or universally configurable.

@michaelficarra
Collaborator

Because you're the only one writing CS on your team, the compiled output can't contain a comment at the top? I think there was a jump in your logic somewhere.

@bclinkinbeard

It's not that it can't, but why should it? The original thread (#1778) points to maintainability as the primary reasoning, to know which version of CS was used, but the top of every single file is hardly the proper place for documenting a project dependency/configuration. Feel free to close this issue if it is a non-starter, it just seems like a very strange thing to enforce universally (with the exception of piped output) and at odds with the spirit of the project.

@michaelficarra
Collaborator

Feel free to close this issue if it is a non-starter

I'll let @jashkenas decide that. I'm not convinced, though. It's useful to know what tool/version generated the JS. And it doesn't hurt to have that metadata around in a comment.

@jashkenas
Owner

I don't really care terribly much either way ... but if you want to send a pull request that does it, and has a really clear and unobtrusive flag for setting it, I think that would be okay.

@michaelficarra
Collaborator

Closing this issue. Feel free to open a pull request as @jashkenas suggested to continue this discussion.

@ProLoser

+1

I use CS and JS intermixed in some projects, and do not get why you feel it's necessary to forcefully impose clutter on my project.

@jchild3rs

As someone leading a UI team, and unfortunately the only one writing CS, I find the comment to be a good thing. If someone needs to work on your stuff and doesn't realize it was written in CS, they will just start editing the compiled JS. That is fail. Big time. The comment makes it obvious.

That being said, I would like an option to remove it. Simply because I like liberty. :)

@ProLoser
ProLoser commented Jul 4, 2012

I don't think anyone is arguing the merits, just the ability to choose.

Sent via Hubroid

@andrewrk
andrewrk commented Jul 7, 2012
// Generated by CoffeeScript 1.3.3
#!/usr/bin/env node;

Fail.

@doublerebel

I propose this change to fix this issue: doublerebel/coffee-script@462fecd

Add flag:

['-g', '--generated',       'Suppress "Generated by" header in compiled JavaScript']

Then in coffee-script.coffee, in exports.compile:

  if (generated = options.generated)?
    if typeof generated is 'function' then (generated js, @VERSION) else js
  else
    header = "Generated by CoffeeScript #{@VERSION}"
    "// #{header}\n#{js}"

This will suppress the "Generated by" header if the flag is set. If compiling programmatically (as I do with vic/tintan), it is possible to pass a function as the generated: flag value. This can solve @superjoe30 's previous comment where shell scripts need to have the interpreter set on the first line -- the function is passed the compiled JS and the version number so that the "Compiled by" line can be customized and placed in the footer or elsewhere.

Without the function feature, a simpler flag-only version could look like this:

  unless options.generated?
    header = "Generated by CoffeeScript #{@VERSION}"
    "// #{header}\n#{js}"
  else js

Opinions? I thought I'd ask first before writing tests. There aren't many single-letter flags left for CoffeeScript, leading me to choose -g/--generated.

@mikesmullin

+1 for doublerebel's fix above

@jescalan

This breaks any file with a shebang up top, which seems like a big deal to me. Has this been resolved?

@jpillora

@superjoe30 👍 @jenius 👍

Can't write command-line JS files with coffeescript due to this...

@vendethiel
Collaborator

due to the shebang ?

@jpillora

Yes, shell is expecting a hash-bang on the first line of the file, though // Generated by ... is placed above it

@michaelficarra
Collaborator

Then add the shebang after the compilation. The compiler generates JavaScript, which doesn't allow shebangs.

@jpillora
jpillora commented Jul 1, 2013

The compiler also provides backtick overrides though for situations exactly like this. It's just the banner that's the problem. Anyway, as mentioned above, with a good PR - it'll get merged. @doublerebel were you going to PR your code ?

@doublerebel

@jpillora I'd be glad to, since I see it has some community support. I'll put it on my short list to update to current stable and make the request.

@jpillora
jpillora commented Jul 5, 2013

Awesome, thanks Charles

On Saturday, July 6, 2013, Charles Phillips wrote:

@jpillora https://github.com/jpillora I'd be glad to, since I see it
has some community support. I'll put it on my short list to update to
current stable and make the request.


Reply to this email directly or view it on GitHubhttps://github.com/jashkenas/coffee-script/issues/2353#issuecomment-20537758
.

@blak3mill3r

I came looking for this feature when I was mapping a keybinding in vim to pipe the current visual block through coffeescript, which I find handy ... not really a big deal, but I did wonder if it was possible to disable the comment.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment