Skip to content
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

Multiline comments broken if contain code with ### #4897

Closed
7v0lk0v opened this issue Feb 13, 2018 · 8 comments
Closed

Multiline comments broken if contain code with ### #4897

7v0lk0v opened this issue Feb 13, 2018 · 8 comments
Labels

Comments

@7v0lk0v
Copy link

7v0lk0v commented Feb 13, 2018

> cat test.coffee
###
console.log '### this should be ignored, not compiled'

console.log '### this too'

console.log '####### and this'
###

> bin/coffee -p test.coffee
(function() {
  /*
  console.log '*/
  this(should(be(ignored, !compiled`console.log `)));

  /* this too'
//##

console.log '*/

}).call(this);

Using latest master: 571e9df

@GeoffreyBooth
Copy link
Collaborator

This is to be expected. JavaScript works the same way:

/*
console.log('*/ oh no, I’m no longer in the comment!')
*/

Comments are like strings, treated as random characters until the next delimiter is encountered.

@Inve1951
Copy link
Contributor

i was under the impression that coffee took care of this by requiring the opening and closing tag to share the same indentation level. i remember getting indentation errors when commenting out code parts without matching them in my early days with coffee.

@GeoffreyBooth
Copy link
Collaborator

@Inve1951 Comments were refactored between 1 and 2, to allow block (###) comments to be inserted anywhere, and to allow line (#) comments to be output into JS. This wasn’t considered a breaking change, because all previously allowed block comments were still allowed in 2; and more cases of block comments became allowed.

However I don’t seem to be able to replicate the “same indentation” requirement you describe. At least in 1.12.7, open and closing ### delimiters don’t seem to need to be at the same level: http://coffeescript.org/v1/#try:%23%23%23%0A%091%0A%09%09%23%23%23. Maybe that was the case in a much older version of CoffeeScript.

@Inve1951
Copy link
Contributor

v2 vs v1
not quite what i described earlier. in v1 the comment opening tag has to be on current indent level or it gives an indent error.

@GeoffreyBooth
Copy link
Collaborator

GeoffreyBooth commented Feb 26, 2018

Yeah, that’s to be expected. In v1 block comments could only exist where expressions could, like where you could put a parenthesized block, whereas in v2 they can now exist anywhere.

@Inve1951
Copy link
Contributor

Inve1951 commented Feb 26, 2018

OP's issue is quite the edge case, indeed. however i feel like there could be a clean solution to it. for example escaping the first hashtag with a backslash.
current workaround is to escape every other # like so:

###
console.log '\##\# this should be ignored, not compiled'

console.log '\##\# this too'

console.log '\##\##\##\# and this'
###

edit: just noticed that you can't open block comments inside string literals. so OP's code compiles fine unless commented out.

@GeoffreyBooth
Copy link
Collaborator

I think the most reasonable solution is to just use an editor that allows commenting out long selections of text. Almost any editor I’ve used, whether a simple text editor or an IDE, allows you to select multiple lines of text and press Cmd-/ or Ctrl-/ to insert #s at the beginning of the line.

@Inve1951
Copy link
Contributor

neat, learned something new

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants