-
Notifications
You must be signed in to change notification settings - Fork 2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Interpolate and indent block comments? #572
Comments
Hmm, the first suggestion is really cool, but it would also be really annoying to unintentionally have something of the form +1 to the second one. It's slightly less byte-efficient, but it's the standard and people expect it. |
Actually, after hearing TrevorBurnham's argument, I think I may have to change my opinion about the automatic interpolation. If I comment out a string with interpolation in it as well as the definition of the variable being interpolated, it will cause a reference error. This might be pretty unexpected behaviour, and the convenience may not be worth the trouble it causes. Even interpolations of the form |
By the way, there's discussion of requiring Re michaelficarra: Maybe the right approach (though it may be a parsing nightmare) is to allow interpolation within block comments except within double quotes, where such interpolations would be valid without the commenting? But I really don't think it's much of an issue. Block comments are supposed to be for things like documentation, not for commenting out code (no reason to preserve commented-out code in the JS output, right?). |
JavaDoc-style asterisk prefixing in block comments is a great idea. As for interpolations, how do we determine the value of a variable at compile-time? Currently there is no notion of a permanent constant in the language, so this would presumably entail actually executing code during its own compilation, which is a minefield of potential side-effects and weird errors. |
@sethaurus: The variables will come from the compiler itself or any files required with the still missing
This would Perhaps interpolations should use another form so it's clear they won't be from scope, i.e., don't expect them to work with variables defined earlier in the script. Back to |
@StanAngeloff thanks for the clarification! |
If a commit I requested a pull on gets merged in (tiny one so fingers crossed), the first part of this issue can be ignored. I gather from the replies everyone's in favour of the second bit about producing nicer looking comments and that should be easy enough to resolve. |
Interpolation in comments isn't going to happen -- that's a pretty strange idea, given that comments "happen" at compile time, not execution time, and should never have anything to do with the surrounding code. Imagine having a syntax error in your comment, and your comment failing to compile... As to the JavaDoc-style comments, that's definitely what we would do if we were compiling to Java -- but we're compiling to JavaScript here, where the style has no special intrinsic significance. Is this just an aesthetic thing, or is there a practical reason to prefer JavaDoc-style comments in JS over simple-style ones? |
I've looked through some of the top JS repos, and the two-thirds majority prefer We talked about it a bit in http://github.com/jashkenas/coffee-script/commit/143c4d5efcab338b7bfcea127b4acc08de5dfb32 Closing the ticket... |
I strongly recommend reverting to
I think it's very desirable for CoffeeScript to support all of these syntaxes. (You could use backtick escapes, of course, but this is bad aesthetics.) Longer-term, if the parsing can be figured out, it would be ideal to preserve line comments in JS output as well, and to give them the |
Thanks jashkenas. I like this approach better and it makes things look much much better in the output. |
Trevor: then what do we emit? The fact that different toolsets treat them differently doesn't seem to be a compelling argument for picking one over the others. Really, what this demonstrates is that it's better to have your build task prepend your license to your minified file, and not bother with learning special minifier directives, no? Feel free to pop into |
I was only suggesting that we emit Requiring people to keep their licenses in separate files is an inconvenience. In my mind, it defeats the main purpose of block comments. |
We've been discussing this for a while in IRC now. There are several related issues at work here. I wanted My proposal is that
should compile to
and
should compile to
should compile to
I think of the main purpose of block comments as being to include licenses in output, and this approach allows CoffeeScript to be consistent with the most common style. What does everyone think? Update: To take an example from Jeremy,
should compile to
|
Relatedly, this currently causes a parse error:
I think there should be an implicit
This is consistent with the way that the TextMate bundle does syntax highlighting, and with the way that an open |
Alright, Trevor, there's a patch now on master with an alteration to the herecomment lexing regex that I think will serve. Here's a bit of Coffee:
And here's the compiled JavaScript that master now generates:
Suit your fancy? |
Coming from #379 (comment), where I was searching for a solution for Markdown formatted JSDoc comments, and the impossibility to write ### inside of those. I couldn't find one from reading this thead. One could expect one of those to work, but none do :
A clarification for this use case would be nice. |
See #1050 also. IMO, that's unfixable as long as we stick to triple-hash. Ironically, CoffeeScript itself suffers from this mischosen syntax wrt Docco: |
I was just browsing through 0.9's online reference and spotted this example:
How about interpolating variables and expressions inside block comments? This would make them much more useful:
One fact I don't like about the output is comments are not indented like regular JavaDoc strings:
It's much more appealing to indent each line so contents appear to be inside the comment:
It is also easier to spot without a syntax highlighter.
The text was updated successfully, but these errors were encountered: