From 9fdb73ae0a2250a369143b89889307f38ab24be8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Hu=C3=A1ng=20J=C3=B9nli=C3=A0ng?= Date: Tue, 21 Jul 2020 16:16:17 -0400 Subject: [PATCH 1/3] fix: check IdentifierReference in PropertyDefinition --- packages/babel-parser/src/parser/expression.js | 2 +- .../destructuring/binding-arguments-module}/input.js | 0 .../destructuring/binding-arguments-module}/output.json | 1 - .../destructuring/binding-arguments-strict}/input.js | 0 .../destructuring/binding-arguments-strict}/options.json | 0 .../destructuring/binding-arguments-strict}/output.json | 1 - .../{uncategorised/333 => destructuring/binding-eval}/input.js | 0 .../333 => destructuring/binding-eval}/output.json | 1 - 8 files changed, 1 insertion(+), 4 deletions(-) rename packages/babel-parser/test/fixtures/{core/uncategorised/547 => es2015/destructuring/binding-arguments-module}/input.js (100%) rename packages/babel-parser/test/fixtures/{core/uncategorised/547 => es2015/destructuring/binding-arguments-module}/output.json (97%) rename packages/babel-parser/test/fixtures/{core/uncategorised/548 => es2015/destructuring/binding-arguments-strict}/input.js (100%) rename packages/babel-parser/test/fixtures/{core/uncategorised/548 => es2015/destructuring/binding-arguments-strict}/options.json (100%) rename packages/babel-parser/test/fixtures/{core/uncategorised/548 => es2015/destructuring/binding-arguments-strict}/output.json (97%) rename packages/babel-parser/test/fixtures/es2015/{uncategorised/333 => destructuring/binding-eval}/input.js (100%) rename packages/babel-parser/test/fixtures/es2015/{uncategorised/333 => destructuring/binding-eval}/output.json (98%) diff --git a/packages/babel-parser/src/parser/expression.js b/packages/babel-parser/src/parser/expression.js index fc8446548d86..3a6baf6e5851 100644 --- a/packages/babel-parser/src/parser/expression.js +++ b/packages/babel-parser/src/parser/expression.js @@ -1788,7 +1788,7 @@ export default class ExpressionParser extends LValParser { } if (!prop.computed && prop.key.type === "Identifier") { - this.checkReservedWord(prop.key.name, prop.key.start, true, true); + this.checkReservedWord(prop.key.name, prop.key.start, true, false); if (isPattern) { prop.value = this.parseMaybeDefault( diff --git a/packages/babel-parser/test/fixtures/core/uncategorised/547/input.js b/packages/babel-parser/test/fixtures/es2015/destructuring/binding-arguments-module/input.js similarity index 100% rename from packages/babel-parser/test/fixtures/core/uncategorised/547/input.js rename to packages/babel-parser/test/fixtures/es2015/destructuring/binding-arguments-module/input.js diff --git a/packages/babel-parser/test/fixtures/core/uncategorised/547/output.json b/packages/babel-parser/test/fixtures/es2015/destructuring/binding-arguments-module/output.json similarity index 97% rename from packages/babel-parser/test/fixtures/core/uncategorised/547/output.json rename to packages/babel-parser/test/fixtures/es2015/destructuring/binding-arguments-module/output.json index c2e81901a1f2..4fb224686603 100644 --- a/packages/babel-parser/test/fixtures/core/uncategorised/547/output.json +++ b/packages/babel-parser/test/fixtures/es2015/destructuring/binding-arguments-module/output.json @@ -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": { diff --git a/packages/babel-parser/test/fixtures/core/uncategorised/548/input.js b/packages/babel-parser/test/fixtures/es2015/destructuring/binding-arguments-strict/input.js similarity index 100% rename from packages/babel-parser/test/fixtures/core/uncategorised/548/input.js rename to packages/babel-parser/test/fixtures/es2015/destructuring/binding-arguments-strict/input.js diff --git a/packages/babel-parser/test/fixtures/core/uncategorised/548/options.json b/packages/babel-parser/test/fixtures/es2015/destructuring/binding-arguments-strict/options.json similarity index 100% rename from packages/babel-parser/test/fixtures/core/uncategorised/548/options.json rename to packages/babel-parser/test/fixtures/es2015/destructuring/binding-arguments-strict/options.json diff --git a/packages/babel-parser/test/fixtures/core/uncategorised/548/output.json b/packages/babel-parser/test/fixtures/es2015/destructuring/binding-arguments-strict/output.json similarity index 97% rename from packages/babel-parser/test/fixtures/core/uncategorised/548/output.json rename to packages/babel-parser/test/fixtures/es2015/destructuring/binding-arguments-strict/output.json index 6065ead49801..66f3fdbdeedf 100644 --- a/packages/babel-parser/test/fixtures/core/uncategorised/548/output.json +++ b/packages/babel-parser/test/fixtures/es2015/destructuring/binding-arguments-strict/output.json @@ -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": { diff --git a/packages/babel-parser/test/fixtures/es2015/uncategorised/333/input.js b/packages/babel-parser/test/fixtures/es2015/destructuring/binding-eval/input.js similarity index 100% rename from packages/babel-parser/test/fixtures/es2015/uncategorised/333/input.js rename to packages/babel-parser/test/fixtures/es2015/destructuring/binding-eval/input.js diff --git a/packages/babel-parser/test/fixtures/es2015/uncategorised/333/output.json b/packages/babel-parser/test/fixtures/es2015/destructuring/binding-eval/output.json similarity index 98% rename from packages/babel-parser/test/fixtures/es2015/uncategorised/333/output.json rename to packages/babel-parser/test/fixtures/es2015/destructuring/binding-eval/output.json index df2a6a81e4b1..9688161107e5 100644 --- a/packages/babel-parser/test/fixtures/es2015/uncategorised/333/output.json +++ b/packages/babel-parser/test/fixtures/es2015/destructuring/binding-eval/output.json @@ -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": { From dfa88e0cc15ba1039093f8ea4611995809289483 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Hu=C3=A1ng=20J=C3=B9nli=C3=A0ng?= Date: Tue, 21 Jul 2020 16:23:08 -0400 Subject: [PATCH 2/3] chore: add more test cases --- .../test/fixtures/es2015/shorthand/1/input.js | 1 - .../fixtures/es2015/shorthand/1/output.json | 62 --------- .../test/fixtures/es2015/shorthand/2/input.js | 1 - .../fixtures/es2015/shorthand/2/output.json | 91 -------------- .../shorthand/get-eval-arguments/input.js | 1 + .../shorthand/get-eval-arguments/output.json | 99 +++++++++++++++ .../shorthand/reserved-word-strict/input.js | 2 + .../reserved-word-strict/output.json | 118 ++++++++++++++++++ .../es2015/shorthand/reserved-word/input.js | 1 + .../shorthand/reserved-word/output.json | 104 +++++++++++++++ 10 files changed, 325 insertions(+), 155 deletions(-) delete mode 100644 packages/babel-parser/test/fixtures/es2015/shorthand/1/input.js delete mode 100644 packages/babel-parser/test/fixtures/es2015/shorthand/1/output.json delete mode 100644 packages/babel-parser/test/fixtures/es2015/shorthand/2/input.js delete mode 100644 packages/babel-parser/test/fixtures/es2015/shorthand/2/output.json create mode 100644 packages/babel-parser/test/fixtures/es2015/shorthand/get-eval-arguments/input.js create mode 100644 packages/babel-parser/test/fixtures/es2015/shorthand/get-eval-arguments/output.json create mode 100644 packages/babel-parser/test/fixtures/es2015/shorthand/reserved-word-strict/input.js create mode 100644 packages/babel-parser/test/fixtures/es2015/shorthand/reserved-word-strict/output.json create mode 100644 packages/babel-parser/test/fixtures/es2015/shorthand/reserved-word/input.js create mode 100644 packages/babel-parser/test/fixtures/es2015/shorthand/reserved-word/output.json diff --git a/packages/babel-parser/test/fixtures/es2015/shorthand/1/input.js b/packages/babel-parser/test/fixtures/es2015/shorthand/1/input.js deleted file mode 100644 index 5ce7c9deac24..000000000000 --- a/packages/babel-parser/test/fixtures/es2015/shorthand/1/input.js +++ /dev/null @@ -1 +0,0 @@ -var x = ({ const }); diff --git a/packages/babel-parser/test/fixtures/es2015/shorthand/1/output.json b/packages/babel-parser/test/fixtures/es2015/shorthand/1/output.json deleted file mode 100644 index 7514d1429f5f..000000000000 --- a/packages/babel-parser/test/fixtures/es2015/shorthand/1/output.json +++ /dev/null @@ -1,62 +0,0 @@ -{ - "type": "File", - "start":0,"end":20,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":20}}, - "errors": [ - "SyntaxError: Unexpected keyword 'const' (1:11)" - ], - "program": { - "type": "Program", - "start":0,"end":20,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":20}}, - "sourceType": "script", - "interpreter": null, - "body": [ - { - "type": "VariableDeclaration", - "start":0,"end":20,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":20}}, - "declarations": [ - { - "type": "VariableDeclarator", - "start":4,"end":19,"loc":{"start":{"line":1,"column":4},"end":{"line":1,"column":19}}, - "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":18,"loc":{"start":{"line":1,"column":9},"end":{"line":1,"column":18}}, - "properties": [ - { - "type": "ObjectProperty", - "start":11,"end":16,"loc":{"start":{"line":1,"column":11},"end":{"line":1,"column":16}}, - "method": false, - "key": { - "type": "Identifier", - "start":11,"end":16,"loc":{"start":{"line":1,"column":11},"end":{"line":1,"column":16},"identifierName":"const"}, - "name": "const" - }, - "computed": false, - "shorthand": true, - "value": { - "type": "Identifier", - "start":11,"end":16,"loc":{"start":{"line":1,"column":11},"end":{"line":1,"column":16},"identifierName":"const"}, - "name": "const" - }, - "extra": { - "shorthand": true - } - } - ], - "extra": { - "parenthesized": true, - "parenStart": 8 - } - } - } - ], - "kind": "var" - } - ], - "directives": [] - } -} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/es2015/shorthand/2/input.js b/packages/babel-parser/test/fixtures/es2015/shorthand/2/input.js deleted file mode 100644 index fabf36837d53..000000000000 --- a/packages/babel-parser/test/fixtures/es2015/shorthand/2/input.js +++ /dev/null @@ -1 +0,0 @@ -({ get, this, if }); diff --git a/packages/babel-parser/test/fixtures/es2015/shorthand/2/output.json b/packages/babel-parser/test/fixtures/es2015/shorthand/2/output.json deleted file mode 100644 index 4ca2311d88fe..000000000000 --- a/packages/babel-parser/test/fixtures/es2015/shorthand/2/output.json +++ /dev/null @@ -1,91 +0,0 @@ -{ - "type": "File", - "start":0,"end":20,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":20}}, - "errors": [ - "SyntaxError: Unexpected keyword 'this' (1:8)", - "SyntaxError: Unexpected keyword 'if' (1:14)" - ], - "program": { - "type": "Program", - "start":0,"end":20,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":20}}, - "sourceType": "script", - "interpreter": null, - "body": [ - { - "type": "ExpressionStatement", - "start":0,"end":20,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":20}}, - "expression": { - "type": "ObjectExpression", - "start":1,"end":18,"loc":{"start":{"line":1,"column":1},"end":{"line":1,"column":18}}, - "properties": [ - { - "type": "ObjectProperty", - "start":3,"end":6,"loc":{"start":{"line":1,"column":3},"end":{"line":1,"column":6}}, - "method": false, - "key": { - "type": "Identifier", - "start":3,"end":6,"loc":{"start":{"line":1,"column":3},"end":{"line":1,"column":6},"identifierName":"get"}, - "name": "get" - }, - "computed": false, - "shorthand": true, - "value": { - "type": "Identifier", - "start":3,"end":6,"loc":{"start":{"line":1,"column":3},"end":{"line":1,"column":6},"identifierName":"get"}, - "name": "get" - }, - "extra": { - "shorthand": true - } - }, - { - "type": "ObjectProperty", - "start":8,"end":12,"loc":{"start":{"line":1,"column":8},"end":{"line":1,"column":12}}, - "method": false, - "key": { - "type": "Identifier", - "start":8,"end":12,"loc":{"start":{"line":1,"column":8},"end":{"line":1,"column":12},"identifierName":"this"}, - "name": "this" - }, - "computed": false, - "shorthand": true, - "value": { - "type": "Identifier", - "start":8,"end":12,"loc":{"start":{"line":1,"column":8},"end":{"line":1,"column":12},"identifierName":"this"}, - "name": "this" - }, - "extra": { - "shorthand": true - } - }, - { - "type": "ObjectProperty", - "start":14,"end":16,"loc":{"start":{"line":1,"column":14},"end":{"line":1,"column":16}}, - "method": false, - "key": { - "type": "Identifier", - "start":14,"end":16,"loc":{"start":{"line":1,"column":14},"end":{"line":1,"column":16},"identifierName":"if"}, - "name": "if" - }, - "computed": false, - "shorthand": true, - "value": { - "type": "Identifier", - "start":14,"end":16,"loc":{"start":{"line":1,"column":14},"end":{"line":1,"column":16},"identifierName":"if"}, - "name": "if" - }, - "extra": { - "shorthand": true - } - } - ], - "extra": { - "parenthesized": true, - "parenStart": 0 - } - } - } - ], - "directives": [] - } -} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/es2015/shorthand/get-eval-arguments/input.js b/packages/babel-parser/test/fixtures/es2015/shorthand/get-eval-arguments/input.js new file mode 100644 index 000000000000..9562ef0e8d01 --- /dev/null +++ b/packages/babel-parser/test/fixtures/es2015/shorthand/get-eval-arguments/input.js @@ -0,0 +1 @@ +var x = ({ get, eval, arguments }); diff --git a/packages/babel-parser/test/fixtures/es2015/shorthand/get-eval-arguments/output.json b/packages/babel-parser/test/fixtures/es2015/shorthand/get-eval-arguments/output.json new file mode 100644 index 000000000000..75790e603e0a --- /dev/null +++ b/packages/babel-parser/test/fixtures/es2015/shorthand/get-eval-arguments/output.json @@ -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": [] + } +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/es2015/shorthand/reserved-word-strict/input.js b/packages/babel-parser/test/fixtures/es2015/shorthand/reserved-word-strict/input.js new file mode 100644 index 000000000000..7127b8e2f8af --- /dev/null +++ b/packages/babel-parser/test/fixtures/es2015/shorthand/reserved-word-strict/input.js @@ -0,0 +1,2 @@ +"use strict"; +var x = ({ implements, interface, package }); diff --git a/packages/babel-parser/test/fixtures/es2015/shorthand/reserved-word-strict/output.json b/packages/babel-parser/test/fixtures/es2015/shorthand/reserved-word-strict/output.json new file mode 100644 index 000000000000..4549edcbc96a --- /dev/null +++ b/packages/babel-parser/test/fixtures/es2015/shorthand/reserved-word-strict/output.json @@ -0,0 +1,118 @@ +{ + "type": "File", + "start":0,"end":59,"loc":{"start":{"line":1,"column":0},"end":{"line":2,"column":45}}, + "errors": [ + "SyntaxError: Unexpected reserved word 'implements' (2:11)", + "SyntaxError: Unexpected reserved word 'interface' (2:23)", + "SyntaxError: Unexpected reserved word 'package' (2:34)" + ], + "program": { + "type": "Program", + "start":0,"end":59,"loc":{"start":{"line":1,"column":0},"end":{"line":2,"column":45}}, + "sourceType": "script", + "interpreter": null, + "body": [ + { + "type": "VariableDeclaration", + "start":14,"end":59,"loc":{"start":{"line":2,"column":0},"end":{"line":2,"column":45}}, + "declarations": [ + { + "type": "VariableDeclarator", + "start":18,"end":58,"loc":{"start":{"line":2,"column":4},"end":{"line":2,"column":44}}, + "id": { + "type": "Identifier", + "start":18,"end":19,"loc":{"start":{"line":2,"column":4},"end":{"line":2,"column":5},"identifierName":"x"}, + "name": "x" + }, + "init": { + "type": "ObjectExpression", + "start":23,"end":57,"loc":{"start":{"line":2,"column":9},"end":{"line":2,"column":43}}, + "properties": [ + { + "type": "ObjectProperty", + "start":25,"end":35,"loc":{"start":{"line":2,"column":11},"end":{"line":2,"column":21}}, + "method": false, + "key": { + "type": "Identifier", + "start":25,"end":35,"loc":{"start":{"line":2,"column":11},"end":{"line":2,"column":21},"identifierName":"implements"}, + "name": "implements" + }, + "computed": false, + "shorthand": true, + "value": { + "type": "Identifier", + "start":25,"end":35,"loc":{"start":{"line":2,"column":11},"end":{"line":2,"column":21},"identifierName":"implements"}, + "name": "implements" + }, + "extra": { + "shorthand": true + } + }, + { + "type": "ObjectProperty", + "start":37,"end":46,"loc":{"start":{"line":2,"column":23},"end":{"line":2,"column":32}}, + "method": false, + "key": { + "type": "Identifier", + "start":37,"end":46,"loc":{"start":{"line":2,"column":23},"end":{"line":2,"column":32},"identifierName":"interface"}, + "name": "interface" + }, + "computed": false, + "shorthand": true, + "value": { + "type": "Identifier", + "start":37,"end":46,"loc":{"start":{"line":2,"column":23},"end":{"line":2,"column":32},"identifierName":"interface"}, + "name": "interface" + }, + "extra": { + "shorthand": true + } + }, + { + "type": "ObjectProperty", + "start":48,"end":55,"loc":{"start":{"line":2,"column":34},"end":{"line":2,"column":41}}, + "method": false, + "key": { + "type": "Identifier", + "start":48,"end":55,"loc":{"start":{"line":2,"column":34},"end":{"line":2,"column":41},"identifierName":"package"}, + "name": "package" + }, + "computed": false, + "shorthand": true, + "value": { + "type": "Identifier", + "start":48,"end":55,"loc":{"start":{"line":2,"column":34},"end":{"line":2,"column":41},"identifierName":"package"}, + "name": "package" + }, + "extra": { + "shorthand": true + } + } + ], + "extra": { + "parenthesized": true, + "parenStart": 22 + } + } + } + ], + "kind": "var" + } + ], + "directives": [ + { + "type": "Directive", + "start":0,"end":13,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":13}}, + "value": { + "type": "DirectiveLiteral", + "start":0,"end":12,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":12}}, + "value": "use strict", + "extra": { + "raw": "\"use strict\"", + "rawValue": "use strict" + } + } + } + ] + } +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/es2015/shorthand/reserved-word/input.js b/packages/babel-parser/test/fixtures/es2015/shorthand/reserved-word/input.js new file mode 100644 index 000000000000..c3cfce102a5a --- /dev/null +++ b/packages/babel-parser/test/fixtures/es2015/shorthand/reserved-word/input.js @@ -0,0 +1 @@ +var x = ({ const, if, this }); diff --git a/packages/babel-parser/test/fixtures/es2015/shorthand/reserved-word/output.json b/packages/babel-parser/test/fixtures/es2015/shorthand/reserved-word/output.json new file mode 100644 index 000000000000..752251aa9b35 --- /dev/null +++ b/packages/babel-parser/test/fixtures/es2015/shorthand/reserved-word/output.json @@ -0,0 +1,104 @@ +{ + "type": "File", + "start":0,"end":30,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":30}}, + "errors": [ + "SyntaxError: Unexpected keyword 'const' (1:11)", + "SyntaxError: Unexpected keyword 'if' (1:18)", + "SyntaxError: Unexpected keyword 'this' (1:22)" + ], + "program": { + "type": "Program", + "start":0,"end":30,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":30}}, + "sourceType": "script", + "interpreter": null, + "body": [ + { + "type": "VariableDeclaration", + "start":0,"end":30,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":30}}, + "declarations": [ + { + "type": "VariableDeclarator", + "start":4,"end":29,"loc":{"start":{"line":1,"column":4},"end":{"line":1,"column":29}}, + "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":28,"loc":{"start":{"line":1,"column":9},"end":{"line":1,"column":28}}, + "properties": [ + { + "type": "ObjectProperty", + "start":11,"end":16,"loc":{"start":{"line":1,"column":11},"end":{"line":1,"column":16}}, + "method": false, + "key": { + "type": "Identifier", + "start":11,"end":16,"loc":{"start":{"line":1,"column":11},"end":{"line":1,"column":16},"identifierName":"const"}, + "name": "const" + }, + "computed": false, + "shorthand": true, + "value": { + "type": "Identifier", + "start":11,"end":16,"loc":{"start":{"line":1,"column":11},"end":{"line":1,"column":16},"identifierName":"const"}, + "name": "const" + }, + "extra": { + "shorthand": true + } + }, + { + "type": "ObjectProperty", + "start":18,"end":20,"loc":{"start":{"line":1,"column":18},"end":{"line":1,"column":20}}, + "method": false, + "key": { + "type": "Identifier", + "start":18,"end":20,"loc":{"start":{"line":1,"column":18},"end":{"line":1,"column":20},"identifierName":"if"}, + "name": "if" + }, + "computed": false, + "shorthand": true, + "value": { + "type": "Identifier", + "start":18,"end":20,"loc":{"start":{"line":1,"column":18},"end":{"line":1,"column":20},"identifierName":"if"}, + "name": "if" + }, + "extra": { + "shorthand": true + } + }, + { + "type": "ObjectProperty", + "start":22,"end":26,"loc":{"start":{"line":1,"column":22},"end":{"line":1,"column":26}}, + "method": false, + "key": { + "type": "Identifier", + "start":22,"end":26,"loc":{"start":{"line":1,"column":22},"end":{"line":1,"column":26},"identifierName":"this"}, + "name": "this" + }, + "computed": false, + "shorthand": true, + "value": { + "type": "Identifier", + "start":22,"end":26,"loc":{"start":{"line":1,"column":22},"end":{"line":1,"column":26},"identifierName":"this"}, + "name": "this" + }, + "extra": { + "shorthand": true + } + } + ], + "extra": { + "parenthesized": true, + "parenStart": 8 + } + } + } + ], + "kind": "var" + } + ], + "directives": [] + } +} \ No newline at end of file From bdce7c30e554016105b08f051b2f010a4dd6970e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Hu=C3=A1ng=20J=C3=B9nli=C3=A0ng?= Date: Wed, 22 Jul 2020 09:42:01 -0400 Subject: [PATCH 3/3] fix: incorrect test title --- .../babel-parser/src/parser/expression.js | 4 ++ .../binding-arguments-module/input.js | 1 - .../options.json | 0 .../binding-arguments-module/output.json | 40 ++++++------------- .../binding-arguments-strict/input.js | 1 + .../binding-arguments-strict/output.json | 40 +++++++++++++------ 6 files changed, 45 insertions(+), 41 deletions(-) rename packages/babel-parser/test/fixtures/es2015/destructuring/{binding-arguments-strict => binding-arguments-module}/options.json (100%) diff --git a/packages/babel-parser/src/parser/expression.js b/packages/babel-parser/src/parser/expression.js index 3a6baf6e5851..1e490ddfd250 100644 --- a/packages/babel-parser/src/parser/expression.js +++ b/packages/babel-parser/src/parser/expression.js @@ -1788,6 +1788,10 @@ export default class ExpressionParser extends LValParser { } if (!prop.computed && prop.key.type === "Identifier") { + // PropertyDefinition: + // IdentifierReference + // CoveredInitializedName + // Note: `{ eval } = {}` will be checked in `checkLVal` later. this.checkReservedWord(prop.key.name, prop.key.start, true, false); if (isPattern) { diff --git a/packages/babel-parser/test/fixtures/es2015/destructuring/binding-arguments-module/input.js b/packages/babel-parser/test/fixtures/es2015/destructuring/binding-arguments-module/input.js index 148e167571ff..d47724793893 100644 --- a/packages/babel-parser/test/fixtures/es2015/destructuring/binding-arguments-module/input.js +++ b/packages/babel-parser/test/fixtures/es2015/destructuring/binding-arguments-module/input.js @@ -1,2 +1 @@ -"use strict"; const { arguments } = foo(); diff --git a/packages/babel-parser/test/fixtures/es2015/destructuring/binding-arguments-strict/options.json b/packages/babel-parser/test/fixtures/es2015/destructuring/binding-arguments-module/options.json similarity index 100% rename from packages/babel-parser/test/fixtures/es2015/destructuring/binding-arguments-strict/options.json rename to packages/babel-parser/test/fixtures/es2015/destructuring/binding-arguments-module/options.json diff --git a/packages/babel-parser/test/fixtures/es2015/destructuring/binding-arguments-module/output.json b/packages/babel-parser/test/fixtures/es2015/destructuring/binding-arguments-module/output.json index 4fb224686603..66f3fdbdeedf 100644 --- a/packages/babel-parser/test/fixtures/es2015/destructuring/binding-arguments-module/output.json +++ b/packages/babel-parser/test/fixtures/es2015/destructuring/binding-arguments-module/output.json @@ -1,40 +1,40 @@ { "type": "File", - "start":0,"end":42,"loc":{"start":{"line":1,"column":0},"end":{"line":2,"column":28}}, + "start":0,"end":28,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":28}}, "errors": [ - "SyntaxError: Binding 'arguments' in strict mode (2:8)" + "SyntaxError: Binding 'arguments' in strict mode (1:8)" ], "program": { "type": "Program", - "start":0,"end":42,"loc":{"start":{"line":1,"column":0},"end":{"line":2,"column":28}}, - "sourceType": "script", + "start":0,"end":28,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":28}}, + "sourceType": "module", "interpreter": null, "body": [ { "type": "VariableDeclaration", - "start":14,"end":42,"loc":{"start":{"line":2,"column":0},"end":{"line":2,"column":28}}, + "start":0,"end":28,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":28}}, "declarations": [ { "type": "VariableDeclarator", - "start":20,"end":41,"loc":{"start":{"line":2,"column":6},"end":{"line":2,"column":27}}, + "start":6,"end":27,"loc":{"start":{"line":1,"column":6},"end":{"line":1,"column":27}}, "id": { "type": "ObjectPattern", - "start":20,"end":33,"loc":{"start":{"line":2,"column":6},"end":{"line":2,"column":19}}, + "start":6,"end":19,"loc":{"start":{"line":1,"column":6},"end":{"line":1,"column":19}}, "properties": [ { "type": "ObjectProperty", - "start":22,"end":31,"loc":{"start":{"line":2,"column":8},"end":{"line":2,"column":17}}, + "start":8,"end":17,"loc":{"start":{"line":1,"column":8},"end":{"line":1,"column":17}}, "method": false, "key": { "type": "Identifier", - "start":22,"end":31,"loc":{"start":{"line":2,"column":8},"end":{"line":2,"column":17},"identifierName":"arguments"}, + "start":8,"end":17,"loc":{"start":{"line":1,"column":8},"end":{"line":1,"column":17},"identifierName":"arguments"}, "name": "arguments" }, "computed": false, "shorthand": true, "value": { "type": "Identifier", - "start":22,"end":31,"loc":{"start":{"line":2,"column":8},"end":{"line":2,"column":17},"identifierName":"arguments"}, + "start":8,"end":17,"loc":{"start":{"line":1,"column":8},"end":{"line":1,"column":17},"identifierName":"arguments"}, "name": "arguments" }, "extra": { @@ -45,10 +45,10 @@ }, "init": { "type": "CallExpression", - "start":36,"end":41,"loc":{"start":{"line":2,"column":22},"end":{"line":2,"column":27}}, + "start":22,"end":27,"loc":{"start":{"line":1,"column":22},"end":{"line":1,"column":27}}, "callee": { "type": "Identifier", - "start":36,"end":39,"loc":{"start":{"line":2,"column":22},"end":{"line":2,"column":25},"identifierName":"foo"}, + "start":22,"end":25,"loc":{"start":{"line":1,"column":22},"end":{"line":1,"column":25},"identifierName":"foo"}, "name": "foo" }, "arguments": [] @@ -58,20 +58,6 @@ "kind": "const" } ], - "directives": [ - { - "type": "Directive", - "start":0,"end":13,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":13}}, - "value": { - "type": "DirectiveLiteral", - "start":0,"end":12,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":12}}, - "value": "use strict", - "extra": { - "raw": "\"use strict\"", - "rawValue": "use strict" - } - } - } - ] + "directives": [] } } \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/es2015/destructuring/binding-arguments-strict/input.js b/packages/babel-parser/test/fixtures/es2015/destructuring/binding-arguments-strict/input.js index d47724793893..148e167571ff 100644 --- a/packages/babel-parser/test/fixtures/es2015/destructuring/binding-arguments-strict/input.js +++ b/packages/babel-parser/test/fixtures/es2015/destructuring/binding-arguments-strict/input.js @@ -1 +1,2 @@ +"use strict"; const { arguments } = foo(); diff --git a/packages/babel-parser/test/fixtures/es2015/destructuring/binding-arguments-strict/output.json b/packages/babel-parser/test/fixtures/es2015/destructuring/binding-arguments-strict/output.json index 66f3fdbdeedf..4fb224686603 100644 --- a/packages/babel-parser/test/fixtures/es2015/destructuring/binding-arguments-strict/output.json +++ b/packages/babel-parser/test/fixtures/es2015/destructuring/binding-arguments-strict/output.json @@ -1,40 +1,40 @@ { "type": "File", - "start":0,"end":28,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":28}}, + "start":0,"end":42,"loc":{"start":{"line":1,"column":0},"end":{"line":2,"column":28}}, "errors": [ - "SyntaxError: Binding 'arguments' in strict mode (1:8)" + "SyntaxError: Binding 'arguments' in strict mode (2:8)" ], "program": { "type": "Program", - "start":0,"end":28,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":28}}, - "sourceType": "module", + "start":0,"end":42,"loc":{"start":{"line":1,"column":0},"end":{"line":2,"column":28}}, + "sourceType": "script", "interpreter": null, "body": [ { "type": "VariableDeclaration", - "start":0,"end":28,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":28}}, + "start":14,"end":42,"loc":{"start":{"line":2,"column":0},"end":{"line":2,"column":28}}, "declarations": [ { "type": "VariableDeclarator", - "start":6,"end":27,"loc":{"start":{"line":1,"column":6},"end":{"line":1,"column":27}}, + "start":20,"end":41,"loc":{"start":{"line":2,"column":6},"end":{"line":2,"column":27}}, "id": { "type": "ObjectPattern", - "start":6,"end":19,"loc":{"start":{"line":1,"column":6},"end":{"line":1,"column":19}}, + "start":20,"end":33,"loc":{"start":{"line":2,"column":6},"end":{"line":2,"column":19}}, "properties": [ { "type": "ObjectProperty", - "start":8,"end":17,"loc":{"start":{"line":1,"column":8},"end":{"line":1,"column":17}}, + "start":22,"end":31,"loc":{"start":{"line":2,"column":8},"end":{"line":2,"column":17}}, "method": false, "key": { "type": "Identifier", - "start":8,"end":17,"loc":{"start":{"line":1,"column":8},"end":{"line":1,"column":17},"identifierName":"arguments"}, + "start":22,"end":31,"loc":{"start":{"line":2,"column":8},"end":{"line":2,"column":17},"identifierName":"arguments"}, "name": "arguments" }, "computed": false, "shorthand": true, "value": { "type": "Identifier", - "start":8,"end":17,"loc":{"start":{"line":1,"column":8},"end":{"line":1,"column":17},"identifierName":"arguments"}, + "start":22,"end":31,"loc":{"start":{"line":2,"column":8},"end":{"line":2,"column":17},"identifierName":"arguments"}, "name": "arguments" }, "extra": { @@ -45,10 +45,10 @@ }, "init": { "type": "CallExpression", - "start":22,"end":27,"loc":{"start":{"line":1,"column":22},"end":{"line":1,"column":27}}, + "start":36,"end":41,"loc":{"start":{"line":2,"column":22},"end":{"line":2,"column":27}}, "callee": { "type": "Identifier", - "start":22,"end":25,"loc":{"start":{"line":1,"column":22},"end":{"line":1,"column":25},"identifierName":"foo"}, + "start":36,"end":39,"loc":{"start":{"line":2,"column":22},"end":{"line":2,"column":25},"identifierName":"foo"}, "name": "foo" }, "arguments": [] @@ -58,6 +58,20 @@ "kind": "const" } ], - "directives": [] + "directives": [ + { + "type": "Directive", + "start":0,"end":13,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":13}}, + "value": { + "type": "DirectiveLiteral", + "start":0,"end":12,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":12}}, + "value": "use strict", + "extra": { + "raw": "\"use strict\"", + "rawValue": "use strict" + } + } + } + ] } } \ No newline at end of file