Skip to content

Commit

Permalink
Correctly check reserved word for PropertyDefinition: IdentifierRefer…
Browse files Browse the repository at this point in the history
…ence (#11862)

* fix: check IdentifierReference in PropertyDefinition

* chore: add more test cases

* fix: incorrect test title
  • Loading branch information
JLHwung committed Jul 29, 2020
1 parent 4ac9c7a commit 01d4625
Show file tree
Hide file tree
Showing 18 changed files with 330 additions and 159 deletions.
6 changes: 5 additions & 1 deletion packages/babel-parser/src/parser/expression.js
Expand Up @@ -1785,7 +1785,11 @@ export default class ExpressionParser extends LValParser {
}

if (!prop.computed && prop.key.type === "Identifier") {
this.checkReservedWord(prop.key.name, prop.key.start, true, true);
// PropertyDefinition:
// IdentifierReference
// CoveredInitializedName
// Note: `{ eval } = {}` will be checked in `checkLVal` later.
this.checkReservedWord(prop.key.name, prop.key.start, true, false);

if (isPattern) {
prop.value = this.parseMaybeDefault(
Expand Down
Expand Up @@ -2,7 +2,6 @@
"type": "File",
"start":0,"end":28,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":28}},
"errors": [
"SyntaxError: Unexpected reserved word 'arguments' (1:8)",
"SyntaxError: Binding 'arguments' in strict mode (1:8)"
],
"program": {
Expand Down
Expand Up @@ -2,7 +2,6 @@
"type": "File",
"start":0,"end":42,"loc":{"start":{"line":1,"column":0},"end":{"line":2,"column":28}},
"errors": [
"SyntaxError: Unexpected reserved word 'arguments' (2:8)",
"SyntaxError: Binding 'arguments' in strict mode (2:8)"
],
"program": {
Expand Down
Expand Up @@ -2,7 +2,6 @@
"type": "File",
"start":0,"end":39,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":39}},
"errors": [
"SyntaxError: Unexpected reserved word 'eval' (1:16)",
"SyntaxError: Assigning to 'eval' in strict mode (1:16)"
],
"program": {
Expand Down

This file was deleted.

62 changes: 0 additions & 62 deletions packages/babel-parser/test/fixtures/es2015/shorthand/1/output.json

This file was deleted.

This file was deleted.

91 changes: 0 additions & 91 deletions packages/babel-parser/test/fixtures/es2015/shorthand/2/output.json

This file was deleted.

@@ -0,0 +1 @@
var x = ({ get, eval, arguments });
@@ -0,0 +1,99 @@
{
"type": "File",
"start":0,"end":35,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":35}},
"program": {
"type": "Program",
"start":0,"end":35,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":35}},
"sourceType": "script",
"interpreter": null,
"body": [
{
"type": "VariableDeclaration",
"start":0,"end":35,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":35}},
"declarations": [
{
"type": "VariableDeclarator",
"start":4,"end":34,"loc":{"start":{"line":1,"column":4},"end":{"line":1,"column":34}},
"id": {
"type": "Identifier",
"start":4,"end":5,"loc":{"start":{"line":1,"column":4},"end":{"line":1,"column":5},"identifierName":"x"},
"name": "x"
},
"init": {
"type": "ObjectExpression",
"start":9,"end":33,"loc":{"start":{"line":1,"column":9},"end":{"line":1,"column":33}},
"properties": [
{
"type": "ObjectProperty",
"start":11,"end":14,"loc":{"start":{"line":1,"column":11},"end":{"line":1,"column":14}},
"method": false,
"key": {
"type": "Identifier",
"start":11,"end":14,"loc":{"start":{"line":1,"column":11},"end":{"line":1,"column":14},"identifierName":"get"},
"name": "get"
},
"computed": false,
"shorthand": true,
"value": {
"type": "Identifier",
"start":11,"end":14,"loc":{"start":{"line":1,"column":11},"end":{"line":1,"column":14},"identifierName":"get"},
"name": "get"
},
"extra": {
"shorthand": true
}
},
{
"type": "ObjectProperty",
"start":16,"end":20,"loc":{"start":{"line":1,"column":16},"end":{"line":1,"column":20}},
"method": false,
"key": {
"type": "Identifier",
"start":16,"end":20,"loc":{"start":{"line":1,"column":16},"end":{"line":1,"column":20},"identifierName":"eval"},
"name": "eval"
},
"computed": false,
"shorthand": true,
"value": {
"type": "Identifier",
"start":16,"end":20,"loc":{"start":{"line":1,"column":16},"end":{"line":1,"column":20},"identifierName":"eval"},
"name": "eval"
},
"extra": {
"shorthand": true
}
},
{
"type": "ObjectProperty",
"start":22,"end":31,"loc":{"start":{"line":1,"column":22},"end":{"line":1,"column":31}},
"method": false,
"key": {
"type": "Identifier",
"start":22,"end":31,"loc":{"start":{"line":1,"column":22},"end":{"line":1,"column":31},"identifierName":"arguments"},
"name": "arguments"
},
"computed": false,
"shorthand": true,
"value": {
"type": "Identifier",
"start":22,"end":31,"loc":{"start":{"line":1,"column":22},"end":{"line":1,"column":31},"identifierName":"arguments"},
"name": "arguments"
},
"extra": {
"shorthand": true
}
}
],
"extra": {
"parenthesized": true,
"parenStart": 8
}
}
}
],
"kind": "var"
}
],
"directives": []
}
}
@@ -0,0 +1,2 @@
"use strict";
var x = ({ implements, interface, package });

0 comments on commit 01d4625

Please sign in to comment.