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
Wrong AST for conditional that looks like arrow #2006
Comments
Yeah, it looks like we disagree with babylon on this parse. It seems pretty ambiguous to me, but we should at least ensure consistency. |
Flow actually doesn't parse this successfully. The |
Looks like both flow (v0.28.0) and babylon (6.8.4, latest on npm) agree now with an unexpected token on the semicolon. var a, b, c, d;
let y = a ? (b) : c => d; // Fails with "Unexpected token ;"
let y = a ? (b) : (c => d); // Parses as desired
let y = a ? (b) : c => d : "foo"; // Also valid |
There is a PR for babylon that makes the first case valid: babel/babylon#59 |
Fixing this might introduce an ambiguity in the language: a ? (b) : c => (d) : e => f How should that expressions be parsed? a ? function (b) : c {
return (d)
} : function (e) {
return f
}
// or
a ? (b) : function (c) {
return function (d) : e {
return f
}
} |
I'm fixing this in babylon (babel/babylon#573); is it ok to throw in ambiguous cases? |
I noticed a bug in flow with this snippet, while trying to fix the same bug in babel/babylon.
Flow creates an ast that looks like this:
but it should be
Tested with flow-parser 0.26 (the latest version on npm)
The text was updated successfully, but these errors were encountered: