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
fix: properly parse member expression after property initializer #11031
Conversation
Fixes issue 10989 where the only the identifier in a member expression that is the value of an object property would be parsed. Removing checkExpressionErrors in parseExprSubscripts results in the subscript also being parsed.
@@ -532,10 +532,6 @@ export default class ExpressionParser extends LValParser { | |||
return expr; | |||
} | |||
|
|||
if (this.checkExpressionErrors(refExpressionErrors, false)) { |
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.
We should investigate if the other this.checkExpressionErrors(refExpressionErrors, false)
checks are necessary. They are not caught by any test cases in babel-parser now.
(They are not even caught by acorn testcases)
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 will look into removing the other instances of this.checkExpressionErrors(refExpressionErrors, false)
. I didn't remove them in this PR because it wasn't necessary to fix the bug, but I can always add some more changes to this PR/open a new one.
Thanks! |
Fixes issue 10989 where only the identifier in a member expression that is the value of an object property would be parsed. Removing
checkExpressionErrors
inparseExprSubscripts
results in the subscript also being parsed.When parsing
({a = 42, b: test.d} = {})
, Babel expects a "," aftertest
. This is because Babel only parsestest
instead oftest.d
. So it expects a comma afterb: test
, since it believes a new object property is starting. This happens because insideparseExprSubscripts
,this.checkExpressionErrors(refExpressionErrors, false)
returnstrue
, which causes the method to return early and not callthis.parseSubscripts(expr, startPos, startLoc)
. Removing that check allowsparseSubscripts
to be called, resulting intest.d
to be parsed as the object property value.