diff --git a/packages/babel-parser/src/parser/expression.js b/packages/babel-parser/src/parser/expression.js index fc8446548d86..1e490ddfd250 100644 --- a/packages/babel-parser/src/parser/expression.js +++ b/packages/babel-parser/src/parser/expression.js @@ -1788,7 +1788,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( diff --git a/packages/babel-parser/test/fixtures/core/uncategorised/548/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/548/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/548/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/core/uncategorised/548/options.json rename to packages/babel-parser/test/fixtures/es2015/destructuring/binding-arguments-module/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-module/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-module/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-module/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/core/uncategorised/547/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/547/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/547/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/547/output.json rename to packages/babel-parser/test/fixtures/es2015/destructuring/binding-arguments-strict/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-strict/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/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": { 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