Skip to content

fix: properly parse member expression after property initializer#11031

Merged
nicolo-ribaudo merged 1 commit intobabel:masterfrom
vedantroy:fix-10989
Jan 19, 2020
Merged

fix: properly parse member expression after property initializer#11031
nicolo-ribaudo merged 1 commit intobabel:masterfrom
vedantroy:fix-10989

Conversation

@vedantroy
Copy link
Copy Markdown
Contributor

@vedantroy vedantroy commented Jan 19, 2020

Fixes issue 10989 where 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.

Q                       A
Fixed Issues? Fixes #10989
Patch: Bug Fix? Yes
Major: Breaking Change? No
Minor: New Feature? No
Tests Added + Pass? Yes
Documentation PR Link No
Any Dependency Changes? No
License MIT

When parsing ({a = 42, b: test.d} = {}), Babel expects a "," after test. This is because Babel only parses test instead of test.d. So it expects a comma after b: test, since it believes a new object property is starting. This happens because inside parseExprSubscripts, this.checkExpressionErrors(refExpressionErrors, false) returns true, which causes the method to return early and not call this.parseSubscripts(expr, startPos, startLoc). Removing that check allows parseSubscripts to be called, resulting in test.d to be parsed as the object property value.

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.
@vedantroy vedantroy requested a review from JLHwung January 19, 2020 21:58
@vedantroy vedantroy changed the title Fixes: #10989 fix: properly parse member expression after property initializer Jan 19, 2020
@JLHwung JLHwung added pkg: parser PR: Spec Compliance 👓 A type of pull request used for our changelog categories labels Jan 19, 2020
return expr;
}

if (this.checkExpressionErrors(refExpressionErrors, false)) {
Copy link
Copy Markdown
Contributor

@JLHwung JLHwung Jan 19, 2020

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)

Copy link
Copy Markdown
Contributor Author

@vedantroy vedantroy Jan 19, 2020

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.

@vedantroy vedantroy requested a review from kaicataldo January 19, 2020 23:02
@nicolo-ribaudo
Copy link
Copy Markdown
Member

Thanks!

@nicolo-ribaudo nicolo-ribaudo merged commit 341964b into babel:master Jan 19, 2020
@nicolo-ribaudo nicolo-ribaudo removed the request for review from kaicataldo January 19, 2020 23:33
@vedantroy vedantroy deleted the fix-10989 branch January 20, 2020 00:53
@github-actions github-actions bot added the outdated A closed issue/PR that is archived due to age. Recommended to make a new issue label Apr 20, 2020
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Apr 20, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

outdated A closed issue/PR that is archived due to age. Recommended to make a new issue pkg: parser PR: Spec Compliance 👓 A type of pull request used for our changelog categories

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Unexpected token when parsing a member expression after a property initializer in an object pattern

3 participants