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

Fail on single line lambda with semicolon #748

Closed
refack opened this issue Jan 13, 2017 · 2 comments
Closed

Fail on single line lambda with semicolon #748

refack opened this issue Jan 13, 2017 · 2 comments
Assignees

Comments

@refack
Copy link
Contributor

refack commented Jan 13, 2017

decaffeinate is producing the wrong JavaScript based on my CoffeeScript input:

foo = () -> null for i in []; t

(repl)

I get this output:

let foo = () => [].map((i) => (null, t));

Here's what I expect it to be instead:
preferably:

let foo = () => {[].map((i) => null); return t}

else at least as if it's a multiline function

let foo = function() { 
  for (let i of []) { null; }
  return t;
};
@alangpierce
Copy link
Member

Thanks for reporting. Looks like the bug is that the normalize step rewrites it as this:

foo = () -> for i in [] then null; t

But I guess it needs to maintain the precedence, maybe by wrapping the loop in parens:

foo = () -> (for i in [] then null); t

@refack
Copy link
Contributor Author

refack commented Jan 13, 2017

LGTM
👍

@alangpierce alangpierce self-assigned this Jan 14, 2017
@alangpierce alangpierce removed their assignment Feb 5, 2017
@alangpierce alangpierce self-assigned this Apr 1, 2017
alangpierce added a commit to alangpierce/decaffeinate that referenced this issue Apr 1, 2017
Fixes decaffeinate#748

`a if b; c` is a conditional followed by a statement, but `if b then a; c` has
`a; c` as the conditional body. To avoid this, we can always wrap these types of
statements in parens if there's a semicolon after them.
alangpierce added a commit that referenced this issue Apr 2, 2017
…943)

Fixes #748

`a if b; c` is a conditional followed by a statement, but `if b then a; c` has
`a; c` as the conditional body. To avoid this, we can always wrap these types of
statements in parens if there's a semicolon after them.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants