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

Duplicate __proto__ key should be allowed in object patterns #10987

Merged
merged 4 commits into from Jan 15, 2020

Conversation

JLHwung
Copy link
Contributor

@JLHwung JLHwung commented Jan 11, 2020

Q                       A
Fixed Issues? Fixes #6705
Patch: Bug Fix? Yes
Tests Added + Pass? Yes
License MIT

This PR can be reviewed commit by commit.

The first commit is to replace refShorthandDefaultPos argument by a new general struct: refExpressionErrors. By doing so we rebrand the refShorthandDefaultPos into a context variable within the expression scope.

This paves the way to fix the duplicate __proto__ tracking issue: In the second commit we add a new property doubleProto to the refExpressionErrors and reset if we are sure the parsed ambiguous object patterns is indeed a LHS.

I have definitely borrowed a lot from acorn's design but carefully crafted parseMaybeAssign to avoid regressions we have solved before.

@JLHwung JLHwung added PR: Spec Compliance 👓 A type of pull request used for our changelog categories pkg: parser labels Jan 11, 2020
@JLHwung JLHwung changed the title Duplicated __proto__ key should be allowed in object patterns Duplicate __proto__ key should be allowed in object patterns Jan 11, 2020
const { shorthandAssign } = refExpressionErrors;
if (!andThrow) return shorthandAssign >= 0;
if (shorthandAssign >= 0) {
this.unexpected(shorthandAssign);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(In a separate PR)
Probably this error would be easily recoverable.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, I try to preserve the error output of shorthand assign error so it's indeed a refactor.

Copy link
Member

@existentialism existentialism left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

@JLHwung JLHwung merged commit 9df70b4 into babel:master Jan 15, 2020
@JLHwung JLHwung deleted the fix-6705 branch January 15, 2020 03: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 15, 2020
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Apr 15, 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.

should allow duplicate __proto__ keys in patterns
3 participants