Skip to content

Comments and extra lines in if...else blocks #394

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

Closed
TrevorBurnham opened this issue May 22, 2010 · 3 comments
Closed

Comments and extra lines in if...else blocks #394

TrevorBurnham opened this issue May 22, 2010 · 3 comments
Labels

Comments

@TrevorBurnham
Copy link
Collaborator

Here's an odd edge case: The following pointless but well-documented piece of code compiles just fine

# Set i = 1 if true
if true
  i = 1

else
  i = 2

as does this

# Set i = 1 if true
if true
  i = 1
# Otherwise, set i = 2
else
  i = 2

but this won't parse:

# Set i = 1 if true
if true
  i = 1

# Otherwise, set i = 2
else
  i = 2
@TrevorBurnham
Copy link
Collaborator Author

Here's a related parse error:

if true
  alert 'All is well'

parses just fine (unfortunately for the user), but

if true
  ###
    Superfluous comment
  ###
  alert 'All is well'

does not.

@jashkenas
Copy link
Owner

After taking a couple failed attempts at solving this cleanly, I've settled on a rather unsatisfactory patch that fixes it:

http://github.com/jashkenas/coffee-script/commit/d9071a80a046967209e7fb935970024d66916bfc

Unhappily enough, comments are the single language feature that is the most difficult to parse in CoffeeScript, largely because they can appear in almost any location within the syntax tree. If anyone can come up with a better scheme for handling them ... it would greatly benefit the codebase.

Closing the ticket.

@GeoffreyBooth
Copy link
Collaborator

if (true) {
  /*
    Superfluous comment
  */
  alert('All is well');
}

is output now, via #4572. Sorry it took awhile.

@GeoffreyBooth GeoffreyBooth removed the bug label Aug 3, 2017
This issue was closed.
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