-
Notifications
You must be signed in to change notification settings - Fork 2k
Fix #3441: parentheses wrapping expression throw invalid error #4849
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
Conversation
src/grammar.coffee
Outdated
# it won't compile since `Parens` (`(b; break)`) is compiled as `Value` and | ||
# pure statement (`break`) can't be used in an expression. | ||
# For this reasons, we return `Block`, which is passed further to `Value` and `Expression`. | ||
stm = $2.contains (n) -> n.constructor.name is 'StatementLiteral' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd rather we don't add such code to the grammar. We can have a node function for that.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also we try not to use constructor.name
for obfuscation reasons IIRC.
src/grammar.coffee
Outdated
@@ -334,7 +334,7 @@ grammar = | |||
o 'Assignable' | |||
o 'Literal', -> new Value $1 | |||
o 'Parenthetical', -> | |||
if $1.constructor.name is 'Parens' | |||
if $1.hasParentheses() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you can use unwrap
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice.
…or (jashkenas#4849) * fix jashkenas#3441 * improvements * refactor
…ariables (#4853) * fix #2047 * Additional check for 'step'; tests * Fix #4105 (#4855) * Update output * Throw warning for unsupported runtimes, e.g. Node < 6 (#4839) * fix #1403 (#4854) * Update output * [Change]: Destructuring with non-final spread should still use rest syntax (#4517) (#4825) * destructuring optimization * refactor * minor improvement, fix errors * minor refactoring * improvements * Update output * Update output * Fix #4843: bad output when assigning to @prop in destructuring assignment with defaults (#4848) * fix #4843 * improvements * typo * small fix * Fix #3441: parentheses wrapping expression throw invalid error (#4849) * fix #3441 * improvements * refactor * Fix #1726: expression in property access causes unexpected results (#4851) * fix #1726 * Explain what's happening, rather than just linking to an issue * Updated output * Optimization * Update output * remove casting to number * cleanup tests
Fixes #3441.
Cases where
statement
is used inside parentheses don't compile:With this PR:
When
Parens
block includes aStatementLiteral
(e.g.(b; break) for a in arr
), it won't compile sinceParens
((b; break)
) is compiled asValue
and pure statement (break
) can't be used in an expression.This PR checks
Parenthetical
rule in the grammar and returnsBlock
instead ofParens
ifStatementLiteral
is detected. TheBlock
node is passed further to theExpression
.