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

Correctly check reserved word for PropertyDefinition: IdentifierReference #11862

Merged
merged 3 commits into from Jul 29, 2020

Conversation

@JLHwung
Copy link
Contributor

JLHwung commented Jul 21, 2020

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

For object shorthand property, e.g. ({ arguments }) is allowed because

PropertyDefinition -> IdentifierReference -> Identifier -> IdentifierName but not ReservedWord

and arguments and eval is not ReservedWord

For destructuring patterns, e.g. ({ arguments = 1 }) = {} is allowed (in sloppy mode) because

PropertyDefinition -> CoverInitializedName -> IdentifierReference -> Identifier -> IdentifierName but not ReservedWord

If the fourth argument of this.checkReservedWord is true, it should be applied on BindingIdentifier, where eval and arguments are forbidden. Therefore the fix here is to align the spec and pass false instead.

This PR fixes a downstream issue: angular/angular-cli#17439

@codesandbox
Copy link

codesandbox bot commented Jul 21, 2020

This pull request is automatically built and testable in CodeSandbox.

To see build info of the built libraries, click here or the icon next to each commit SHA.

Latest deployment of this branch, based on commit bdce7c3:

Sandbox Source
babel-repl-custom-plugin Configuration
babel-plugin-multi-config Configuration
@babel-bot
Copy link
Collaborator

babel-bot commented Jul 21, 2020

Build successful! You can test your changes in the REPL here: https://babeljs.io/repl/build/26313/

@nicolo-ribaudo
Copy link
Member

nicolo-ribaudo commented Jul 22, 2020

For destructuring patterns, e.g. ({ arguments = 1 }) = {} is allowed because

I don't think so: the destructuring pattern must match the "AssignmentPattern" production, and:

12.15.7.1 Static Semantics: Early Errors

AssignmentProperty : IdentifierReference Initializer[opt]

  • It is a Syntax Error if AssignmentTargetType of IdentifierReference is not simple.

12.1.3 Static Semantics: AssignmentTargetType

IdentifierReference : Identifier

  1. If this IdentifierReference is contained in strict mode code and StringValue of Identifier is "eval" or "arguments", return invalid.
  2. Return simple.
@JLHwung
Copy link
Contributor Author

JLHwung commented Jul 22, 2020

If this IdentifierReference is contained in strict mode code and StringValue of Identifier is "eval" or "arguments", return invalid.

As for destructuring, we will check the BindingIdentifier ReservedWord in checkLVal later:

this.state.strict &&
// "Global" reserved words have already been checked by parseIdentifier,
// unless they have been found in the id or parameters of a strict-mode
// function in a sloppy context.
(strictModeChanged
? isStrictBindReservedWord(expr.name, this.inModule)
: isStrictBindOnlyReservedWord(expr.name))

Thus the following test case still throws.

"use strict";
const { arguments } = foo();

Since we can not differentiate between CoverInitializedName and AssignmentProperty until we see an = or =>, I think the change here is okay.

@hzoo
hzoo approved these changes Jul 29, 2020
@JLHwung JLHwung merged commit 01d4625 into babel:main Jul 29, 2020
8 of 9 checks passed
8 of 9 checks passed
build
Details
test262-pr Workflow: test262-pr
Details
Gitpod Open an online workspace in Gitpod
Details
Travis CI - Pull Request Build Passed
Details
babel/repl REPL preview is available
Details
build-standalone Workflow: build-standalone
Details
ci/codesandbox Building packages succeeded.
Details
codecov/project 91.85% (target 90.00%)
Details
e2e Workflow: e2e
Details
@JLHwung JLHwung deleted the JLHwung:fix-10411 branch Jul 29, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked issues

Successfully merging this pull request may close these issues.

5 participants
You can’t perform that action at this time.