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

wrapping when clause in paren causes error #502

Closed
leonyu opened this issue Oct 30, 2016 · 0 comments · Fixed by decaffeinate/decaffeinate-parser#74
Closed

wrapping when clause in paren causes error #502

leonyu opened this issue Oct 30, 2016 · 0 comments · Fixed by decaffeinate/decaffeinate-parser#74
Assignees

Comments

@leonyu
Copy link

leonyu commented Oct 30, 2016

decaffeinate is crashing on my CoffeeScript input:

x for a in [1,2,3] when (x == 1)

http://decaffeinate-project.org/repl/#?evaluate=true&stage=full&code=x%20for%20a%20in%20%5B1%2C2%2C3%5D%20when%20(x%20%3D%3D%201)

I get this error:

MainStage failed to parse: unexpected then
> 1 | for a in [1,2,3] when (x == 1 then x)
    |                               ^^^^
@leonyu leonyu changed the title wrapping when clause in paren cause error wrapping when clause in paren causes error Oct 30, 2016
@alangpierce alangpierce self-assigned this Nov 13, 2016
alangpierce added a commit to alangpierce/decaffeinate-parser that referenced this issue Nov 13, 2016
Fixes decaffeinate/decaffeinate#333
Fixes decaffeinate/decaffeinate#502

The code to fix CoffeeScript location data was incorrectly assuming that the
last node of a loop is the loop body, but that isn't true in postfix loops, so
it was causing the end location to be artificially early. Probably, the ideal
behavior (assuming location data actually needs to be fixed here) is to take the
max of all nodes, but that didn't seem trivial. Instead, an easy fix is to just
do the same thing we do for the `if` case: just use the body to extend the
bounds if necessary, but never shrink it. This also seems more robust in
general, probably. At the very least, it's really simple and doesn't break any
decaffeinate tests.
alangpierce added a commit to decaffeinate/decaffeinate-parser that referenced this issue Nov 13, 2016
Fixes decaffeinate/decaffeinate#333
Fixes decaffeinate/decaffeinate#502

The code to fix CoffeeScript location data was incorrectly assuming that the
last node of a loop is the loop body, but that isn't true in postfix loops, so
it was causing the end location to be artificially early. Probably, the ideal
behavior (assuming location data actually needs to be fixed here) is to take the
max of all nodes, but that didn't seem trivial. Instead, an easy fix is to just
do the same thing we do for the `if` case: just use the body to extend the
bounds if necessary, but never shrink it. This also seems more robust in
general, probably. At the very least, it's really simple and doesn't break any
decaffeinate tests.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants