diff --git a/packages/babel-parser/src/parser/error-message.js b/packages/babel-parser/src/parser/error-message.js index 4fb6c3ddfcce..be13d613aeb4 100644 --- a/packages/babel-parser/src/parser/error-message.js +++ b/packages/babel-parser/src/parser/error-message.js @@ -78,6 +78,7 @@ export const ErrorMessages = makeErrorTemplates( ImportCallSpreadArgument: "`...` is not allowed in `import()`.", InvalidBigIntLiteral: "Invalid BigIntLiteral.", InvalidCodePoint: "Code point out of bounds.", + InvalidCoverInitializedName: "Invalid shorthand property initializer.", InvalidDecimal: "Invalid decimal.", InvalidDigit: "Expected number in radix %0.", InvalidEscapeSequence: "Bad character escape sequence.", diff --git a/packages/babel-parser/src/parser/expression.js b/packages/babel-parser/src/parser/expression.js index 3b0af6521f11..e221d4d978ff 100644 --- a/packages/babel-parser/src/parser/expression.js +++ b/packages/babel-parser/src/parser/expression.js @@ -770,24 +770,17 @@ export default class ExpressionParser extends LValParser { const node = this.startNodeAt(startPos, startLoc); node.object = base; node.computed = computed; - const privateName = - !computed && this.match(tt.privateName) && this.state.value; - const property = computed - ? this.parseExpression() - : privateName - ? this.parsePrivateName() - : this.parseIdentifier(true); - - if (privateName !== false) { - if (node.object.type === "Super") { - this.raise(startPos, Errors.SuperPrivateField); - } - this.classScope.usePrivateName(privateName, property.start); - } - node.property = property; - if (computed) { + node.property = this.parseExpression(); this.expect(tt.bracketR); + } else if (this.match(tt.privateName)) { + if (base.type === "Super") { + this.raise(startPos, Errors.SuperPrivateField); + } + this.classScope.usePrivateName(this.state.value, this.state.start); + node.property = this.parsePrivateName(); + } else { + node.property = this.parseIdentifier(true); } if (state.optionalChainMember) { @@ -2137,7 +2130,7 @@ export default class ExpressionParser extends LValParser { if (!prop.computed && prop.key.type === "Identifier") { // PropertyDefinition: // IdentifierReference - // CoveredInitializedName + // CoverInitializedName // Note: `{ eval } = {}` will be checked in `checkLVal` later. this.checkReservedWord(prop.key.name, prop.key.start, true, false); @@ -2147,9 +2140,14 @@ export default class ExpressionParser extends LValParser { startLoc, cloneIdentifier(prop.key), ); - } else if (this.match(tt.eq) && refExpressionErrors) { - if (refExpressionErrors.shorthandAssign === -1) { - refExpressionErrors.shorthandAssign = this.state.start; + } else if (this.match(tt.eq)) { + const shorthandAssign = this.state.start; + if (refExpressionErrors != null) { + if (refExpressionErrors.shorthandAssign === -1) { + refExpressionErrors.shorthandAssign = shorthandAssign; + } + } else { + this.raise(shorthandAssign, Errors.InvalidCoverInitializedName); } prop.value = this.parseMaybeDefault( startPos, diff --git a/packages/babel-parser/src/parser/util.js b/packages/babel-parser/src/parser/util.js index 3ad3bc4b795e..8e06034eca01 100644 --- a/packages/babel-parser/src/parser/util.js +++ b/packages/babel-parser/src/parser/util.js @@ -270,7 +270,7 @@ export default class UtilParser extends Tokenizer { return hasErrors; } else if (hasErrors) { if (shorthandAssign >= 0) { - this.unexpected(shorthandAssign); + this.raise(shorthandAssign, Errors.InvalidCoverInitializedName); } if (doubleProto >= 0) { this.raise(doubleProto, Errors.DuplicateProto); diff --git a/packages/babel-parser/src/util/class-scope.js b/packages/babel-parser/src/util/class-scope.js index e5b973f7c0c8..70920d1b68ab 100644 --- a/packages/babel-parser/src/util/class-scope.js +++ b/packages/babel-parser/src/util/class-scope.js @@ -61,11 +61,12 @@ export default class ClassScopeHandler { elementType: ClassElementTypes, pos: number, ) { - const classScope = this.current(); - let redefined = classScope.privateNames.has(name); + const { privateNames, loneAccessors, undefinedPrivateNames } = + this.current(); + let redefined = privateNames.has(name); if (elementType & CLASS_ELEMENT_KIND_ACCESSOR) { - const accessor = redefined && classScope.loneAccessors.get(name); + const accessor = redefined && loneAccessors.get(name); if (accessor) { const oldStatic = accessor & CLASS_ELEMENT_FLAG_STATIC; const newStatic = elementType & CLASS_ELEMENT_FLAG_STATIC; @@ -78,9 +79,9 @@ export default class ClassScopeHandler { // they have the same placement (static or not). redefined = oldKind === newKind || oldStatic !== newStatic; - if (!redefined) classScope.loneAccessors.delete(name); + if (!redefined) loneAccessors.delete(name); } else if (!redefined) { - classScope.loneAccessors.set(name, elementType); + loneAccessors.set(name, elementType); } } @@ -88,8 +89,8 @@ export default class ClassScopeHandler { this.raise(pos, Errors.PrivateNameRedeclaration, name); } - classScope.privateNames.add(name); - classScope.undefinedPrivateNames.delete(name); + privateNames.add(name); + undefinedPrivateNames.delete(name); } usePrivateName(name: string, pos: number) { diff --git a/packages/babel-parser/test/fixtures/core/object/invalid-property-initializer-1/options.json b/packages/babel-parser/test/fixtures/core/object/invalid-property-initializer-1/options.json deleted file mode 100644 index e92fc4e28742..000000000000 --- a/packages/babel-parser/test/fixtures/core/object/invalid-property-initializer-1/options.json +++ /dev/null @@ -1,3 +0,0 @@ -{ - "throws": "Unexpected token (3:6)" -} diff --git a/packages/babel-parser/test/fixtures/core/object/invalid-property-initializer/options.json b/packages/babel-parser/test/fixtures/core/object/invalid-property-initializer/options.json deleted file mode 100644 index 9660494a29ea..000000000000 --- a/packages/babel-parser/test/fixtures/core/object/invalid-property-initializer/options.json +++ /dev/null @@ -1,3 +0,0 @@ -{ - "throws": "Unexpected token (2:6)" -} diff --git a/packages/babel-parser/test/fixtures/core/object/invalid-property-initializer-1/input.js b/packages/babel-parser/test/fixtures/es2015/object/invalid-property-initializer-1/input.js similarity index 100% rename from packages/babel-parser/test/fixtures/core/object/invalid-property-initializer-1/input.js rename to packages/babel-parser/test/fixtures/es2015/object/invalid-property-initializer-1/input.js diff --git a/packages/babel-parser/test/fixtures/es2015/object/invalid-property-initializer-1/output.json b/packages/babel-parser/test/fixtures/es2015/object/invalid-property-initializer-1/output.json new file mode 100644 index 000000000000..2c6ce53de29a --- /dev/null +++ b/packages/babel-parser/test/fixtures/es2015/object/invalid-property-initializer-1/output.json @@ -0,0 +1,102 @@ +{ + "type": "File", + "start":0,"end":44,"loc":{"start":{"line":1,"column":0},"end":{"line":4,"column":2}}, + "errors": [ + "SyntaxError: Invalid shorthand property initializer. (3:6)" + ], + "program": { + "type": "Program", + "start":0,"end":44,"loc":{"start":{"line":1,"column":0},"end":{"line":4,"column":2}}, + "sourceType": "script", + "interpreter": null, + "body": [ + { + "type": "VariableDeclaration", + "start":0,"end":44,"loc":{"start":{"line":1,"column":0},"end":{"line":4,"column":2}}, + "declarations": [ + { + "type": "VariableDeclarator", + "start":6,"end":43,"loc":{"start":{"line":1,"column":6},"end":{"line":4,"column":1}}, + "id": { + "type": "Identifier", + "start":6,"end":9,"loc":{"start":{"line":1,"column":6},"end":{"line":1,"column":9},"identifierName":"obj"}, + "name": "obj" + }, + "init": { + "type": "ObjectExpression", + "start":12,"end":43,"loc":{"start":{"line":1,"column":12},"end":{"line":4,"column":1}}, + "properties": [ + { + "type": "ObjectProperty", + "start":16,"end":28,"loc":{"start":{"line":2,"column":2},"end":{"line":2,"column":14}}, + "method": false, + "key": { + "type": "Identifier", + "start":16,"end":19,"loc":{"start":{"line":2,"column":2},"end":{"line":2,"column":5},"identifierName":"bar"}, + "name": "bar" + }, + "computed": false, + "shorthand": false, + "value": { + "type": "AssignmentExpression", + "start":21,"end":28,"loc":{"start":{"line":2,"column":7},"end":{"line":2,"column":14}}, + "operator": "=", + "left": { + "type": "Identifier", + "start":21,"end":22,"loc":{"start":{"line":2,"column":7},"end":{"line":2,"column":8},"identifierName":"x"}, + "name": "x" + }, + "right": { + "type": "NumericLiteral", + "start":25,"end":28,"loc":{"start":{"line":2,"column":11},"end":{"line":2,"column":14}}, + "extra": { + "rawValue": 123, + "raw": "123" + }, + "value": 123 + } + } + }, + { + "type": "ObjectProperty", + "start":32,"end":41,"loc":{"start":{"line":3,"column":2},"end":{"line":3,"column":11}}, + "method": false, + "key": { + "type": "Identifier", + "start":32,"end":35,"loc":{"start":{"line":3,"column":2},"end":{"line":3,"column":5},"identifierName":"foo"}, + "name": "foo" + }, + "computed": false, + "shorthand": true, + "value": { + "type": "AssignmentPattern", + "start":32,"end":41,"loc":{"start":{"line":3,"column":2},"end":{"line":3,"column":11}}, + "left": { + "type": "Identifier", + "start":32,"end":35,"loc":{"start":{"line":3,"column":2},"end":{"line":3,"column":5},"identifierName":"foo"}, + "name": "foo" + }, + "right": { + "type": "NumericLiteral", + "start":38,"end":41,"loc":{"start":{"line":3,"column":8},"end":{"line":3,"column":11}}, + "extra": { + "rawValue": 123, + "raw": "123" + }, + "value": 123 + } + }, + "extra": { + "shorthand": true + } + } + ] + } + } + ], + "kind": "const" + } + ], + "directives": [] + } +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/es2015/uncategorised/312/input.js b/packages/babel-parser/test/fixtures/es2015/object/invalid-property-initializer-in-call/input.js similarity index 100% rename from packages/babel-parser/test/fixtures/es2015/uncategorised/312/input.js rename to packages/babel-parser/test/fixtures/es2015/object/invalid-property-initializer-in-call/input.js diff --git a/packages/babel-parser/test/fixtures/es2015/object/invalid-property-initializer-in-call/output.json b/packages/babel-parser/test/fixtures/es2015/object/invalid-property-initializer-in-call/output.json new file mode 100644 index 000000000000..e1d212582356 --- /dev/null +++ b/packages/babel-parser/test/fixtures/es2015/object/invalid-property-initializer-in-call/output.json @@ -0,0 +1,70 @@ +{ + "type": "File", + "start":0,"end":10,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":10}}, + "errors": [ + "SyntaxError: Invalid shorthand property initializer. (1:5)" + ], + "program": { + "type": "Program", + "start":0,"end":10,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":10}}, + "sourceType": "script", + "interpreter": null, + "body": [ + { + "type": "ExpressionStatement", + "start":0,"end":10,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":10}}, + "expression": { + "type": "CallExpression", + "start":0,"end":10,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":10}}, + "callee": { + "type": "Identifier", + "start":0,"end":1,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":1},"identifierName":"f"}, + "name": "f" + }, + "arguments": [ + { + "type": "ObjectExpression", + "start":2,"end":9,"loc":{"start":{"line":1,"column":2},"end":{"line":1,"column":9}}, + "properties": [ + { + "type": "ObjectProperty", + "start":3,"end":8,"loc":{"start":{"line":1,"column":3},"end":{"line":1,"column":8}}, + "method": false, + "key": { + "type": "Identifier", + "start":3,"end":4,"loc":{"start":{"line":1,"column":3},"end":{"line":1,"column":4},"identifierName":"x"}, + "name": "x" + }, + "computed": false, + "shorthand": true, + "value": { + "type": "AssignmentPattern", + "start":3,"end":8,"loc":{"start":{"line":1,"column":3},"end":{"line":1,"column":8}}, + "left": { + "type": "Identifier", + "start":3,"end":4,"loc":{"start":{"line":1,"column":3},"end":{"line":1,"column":4},"identifierName":"x"}, + "name": "x" + }, + "right": { + "type": "NumericLiteral", + "start":7,"end":8,"loc":{"start":{"line":1,"column":7},"end":{"line":1,"column":8}}, + "extra": { + "rawValue": 0, + "raw": "0" + }, + "value": 0 + } + }, + "extra": { + "shorthand": true + } + } + ] + } + ] + } + } + ], + "directives": [] + } +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/es2015/uncategorised/311/input.js b/packages/babel-parser/test/fixtures/es2015/object/invalid-property-initializer-in-rhs/input.js similarity index 100% rename from packages/babel-parser/test/fixtures/es2015/uncategorised/311/input.js rename to packages/babel-parser/test/fixtures/es2015/object/invalid-property-initializer-in-rhs/input.js diff --git a/packages/babel-parser/test/fixtures/es2015/object/invalid-property-initializer-in-rhs/output.json b/packages/babel-parser/test/fixtures/es2015/object/invalid-property-initializer-in-rhs/output.json new file mode 100644 index 000000000000..cc80d7fe6b75 --- /dev/null +++ b/packages/babel-parser/test/fixtures/es2015/object/invalid-property-initializer-in-rhs/output.json @@ -0,0 +1,69 @@ +{ + "type": "File", + "start":0,"end":13,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":13}}, + "errors": [ + "SyntaxError: Invalid shorthand property initializer. (1:9)" + ], + "program": { + "type": "Program", + "start":0,"end":13,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":13}}, + "sourceType": "script", + "interpreter": null, + "body": [ + { + "type": "ExpressionStatement", + "start":0,"end":13,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":13}}, + "expression": { + "type": "AssignmentExpression", + "start":0,"end":13,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":13}}, + "operator": "=", + "left": { + "type": "Identifier", + "start":0,"end":3,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":3},"identifierName":"obj"}, + "name": "obj" + }, + "right": { + "type": "ObjectExpression", + "start":6,"end":13,"loc":{"start":{"line":1,"column":6},"end":{"line":1,"column":13}}, + "properties": [ + { + "type": "ObjectProperty", + "start":7,"end":12,"loc":{"start":{"line":1,"column":7},"end":{"line":1,"column":12}}, + "method": false, + "key": { + "type": "Identifier", + "start":7,"end":8,"loc":{"start":{"line":1,"column":7},"end":{"line":1,"column":8},"identifierName":"x"}, + "name": "x" + }, + "computed": false, + "shorthand": true, + "value": { + "type": "AssignmentPattern", + "start":7,"end":12,"loc":{"start":{"line":1,"column":7},"end":{"line":1,"column":12}}, + "left": { + "type": "Identifier", + "start":7,"end":8,"loc":{"start":{"line":1,"column":7},"end":{"line":1,"column":8},"identifierName":"x"}, + "name": "x" + }, + "right": { + "type": "NumericLiteral", + "start":11,"end":12,"loc":{"start":{"line":1,"column":11},"end":{"line":1,"column":12}}, + "extra": { + "rawValue": 0, + "raw": "0" + }, + "value": 0 + } + }, + "extra": { + "shorthand": true + } + } + ] + } + } + } + ], + "directives": [] + } +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/core/object/invalid-property-initializer/input.js b/packages/babel-parser/test/fixtures/es2015/object/invalid-property-initializer/input.js similarity index 100% rename from packages/babel-parser/test/fixtures/core/object/invalid-property-initializer/input.js rename to packages/babel-parser/test/fixtures/es2015/object/invalid-property-initializer/input.js diff --git a/packages/babel-parser/test/fixtures/es2015/object/invalid-property-initializer/output.json b/packages/babel-parser/test/fixtures/es2015/object/invalid-property-initializer/output.json new file mode 100644 index 000000000000..063cb80380f5 --- /dev/null +++ b/packages/babel-parser/test/fixtures/es2015/object/invalid-property-initializer/output.json @@ -0,0 +1,102 @@ +{ + "type": "File", + "start":0,"end":44,"loc":{"start":{"line":1,"column":0},"end":{"line":4,"column":2}}, + "errors": [ + "SyntaxError: Invalid shorthand property initializer. (2:6)" + ], + "program": { + "type": "Program", + "start":0,"end":44,"loc":{"start":{"line":1,"column":0},"end":{"line":4,"column":2}}, + "sourceType": "script", + "interpreter": null, + "body": [ + { + "type": "VariableDeclaration", + "start":0,"end":44,"loc":{"start":{"line":1,"column":0},"end":{"line":4,"column":2}}, + "declarations": [ + { + "type": "VariableDeclarator", + "start":6,"end":43,"loc":{"start":{"line":1,"column":6},"end":{"line":4,"column":1}}, + "id": { + "type": "Identifier", + "start":6,"end":9,"loc":{"start":{"line":1,"column":6},"end":{"line":1,"column":9},"identifierName":"obj"}, + "name": "obj" + }, + "init": { + "type": "ObjectExpression", + "start":12,"end":43,"loc":{"start":{"line":1,"column":12},"end":{"line":4,"column":1}}, + "properties": [ + { + "type": "ObjectProperty", + "start":16,"end":25,"loc":{"start":{"line":2,"column":2},"end":{"line":2,"column":11}}, + "method": false, + "key": { + "type": "Identifier", + "start":16,"end":19,"loc":{"start":{"line":2,"column":2},"end":{"line":2,"column":5},"identifierName":"foo"}, + "name": "foo" + }, + "computed": false, + "shorthand": true, + "value": { + "type": "AssignmentPattern", + "start":16,"end":25,"loc":{"start":{"line":2,"column":2},"end":{"line":2,"column":11}}, + "left": { + "type": "Identifier", + "start":16,"end":19,"loc":{"start":{"line":2,"column":2},"end":{"line":2,"column":5},"identifierName":"foo"}, + "name": "foo" + }, + "right": { + "type": "NumericLiteral", + "start":22,"end":25,"loc":{"start":{"line":2,"column":8},"end":{"line":2,"column":11}}, + "extra": { + "rawValue": 123, + "raw": "123" + }, + "value": 123 + } + }, + "extra": { + "shorthand": true + } + }, + { + "type": "ObjectProperty", + "start":29,"end":41,"loc":{"start":{"line":3,"column":2},"end":{"line":3,"column":14}}, + "method": false, + "key": { + "type": "Identifier", + "start":29,"end":32,"loc":{"start":{"line":3,"column":2},"end":{"line":3,"column":5},"identifierName":"bar"}, + "name": "bar" + }, + "computed": false, + "shorthand": false, + "value": { + "type": "AssignmentExpression", + "start":34,"end":41,"loc":{"start":{"line":3,"column":7},"end":{"line":3,"column":14}}, + "operator": "=", + "left": { + "type": "Identifier", + "start":34,"end":35,"loc":{"start":{"line":3,"column":7},"end":{"line":3,"column":8},"identifierName":"x"}, + "name": "x" + }, + "right": { + "type": "NumericLiteral", + "start":38,"end":41,"loc":{"start":{"line":3,"column":11},"end":{"line":3,"column":14}}, + "extra": { + "rawValue": 123, + "raw": "123" + }, + "value": 123 + } + } + } + ] + } + } + ], + "kind": "const" + } + ], + "directives": [] + } +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/es2015/uncategorised/311/options.json b/packages/babel-parser/test/fixtures/es2015/uncategorised/311/options.json deleted file mode 100644 index 2a28555f76db..000000000000 --- a/packages/babel-parser/test/fixtures/es2015/uncategorised/311/options.json +++ /dev/null @@ -1,3 +0,0 @@ -{ - "throws": "Unexpected token (1:9)" -} diff --git a/packages/babel-parser/test/fixtures/es2015/uncategorised/312/options.json b/packages/babel-parser/test/fixtures/es2015/uncategorised/312/options.json deleted file mode 100644 index 91b308200e05..000000000000 --- a/packages/babel-parser/test/fixtures/es2015/uncategorised/312/options.json +++ /dev/null @@ -1,3 +0,0 @@ -{ - "throws": "Unexpected token (1:5)" -} diff --git a/packages/babel-parser/test/fixtures/es2017/async-call/parenthesized-argument-object-with-assignment/options.json b/packages/babel-parser/test/fixtures/es2017/async-call/parenthesized-argument-object-with-assignment/options.json deleted file mode 100644 index 51c483f3d3d8..000000000000 --- a/packages/babel-parser/test/fixtures/es2017/async-call/parenthesized-argument-object-with-assignment/options.json +++ /dev/null @@ -1,3 +0,0 @@ -{ - "throws": "Unexpected token (1:14)" -} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/es2017/async-call/parenthesized-argument-object-with-assignment/output.json b/packages/babel-parser/test/fixtures/es2017/async-call/parenthesized-argument-object-with-assignment/output.json new file mode 100644 index 000000000000..0ef1eefb0898 --- /dev/null +++ b/packages/babel-parser/test/fixtures/es2017/async-call/parenthesized-argument-object-with-assignment/output.json @@ -0,0 +1,70 @@ +{ + "type": "File", + "start":0,"end":21,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":21}}, + "errors": [ + "SyntaxError: Invalid shorthand property initializer. (1:14)" + ], + "program": { + "type": "Program", + "start":0,"end":21,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":21}}, + "sourceType": "script", + "interpreter": null, + "body": [ + { + "type": "ExpressionStatement", + "start":0,"end":21,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":21}}, + "expression": { + "type": "CallExpression", + "start":0,"end":20,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":20}}, + "callee": { + "type": "Identifier", + "start":0,"end":5,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":5},"identifierName":"async"}, + "name": "async" + }, + "arguments": [ + { + "type": "ObjectExpression", + "start":6,"end":19,"loc":{"start":{"line":1,"column":6},"end":{"line":1,"column":19}}, + "properties": [ + { + "type": "ObjectProperty", + "start":8,"end":17,"loc":{"start":{"line":1,"column":8},"end":{"line":1,"column":17}}, + "method": false, + "key": { + "type": "Identifier", + "start":8,"end":13,"loc":{"start":{"line":1,"column":8},"end":{"line":1,"column":13},"identifierName":"foo33"}, + "name": "foo33" + }, + "computed": false, + "shorthand": true, + "value": { + "type": "AssignmentPattern", + "start":8,"end":17,"loc":{"start":{"line":1,"column":8},"end":{"line":1,"column":17}}, + "left": { + "type": "Identifier", + "start":8,"end":13,"loc":{"start":{"line":1,"column":8},"end":{"line":1,"column":13},"identifierName":"foo33"}, + "name": "foo33" + }, + "right": { + "type": "NumericLiteral", + "start":16,"end":17,"loc":{"start":{"line":1,"column":16},"end":{"line":1,"column":17}}, + "extra": { + "rawValue": 1, + "raw": "1" + }, + "value": 1 + } + }, + "extra": { + "shorthand": true + } + } + ] + } + ] + } + } + ], + "directives": [] + } +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/es2017/async-functions/35/options.json b/packages/babel-parser/test/fixtures/es2017/async-functions/35/options.json deleted file mode 100644 index 0de5e62369ae..000000000000 --- a/packages/babel-parser/test/fixtures/es2017/async-functions/35/options.json +++ /dev/null @@ -1,3 +0,0 @@ -{ - "throws": "Unexpected token (1:20)" -} diff --git a/packages/babel-parser/test/fixtures/es2017/async-functions/35/output.json b/packages/babel-parser/test/fixtures/es2017/async-functions/35/output.json new file mode 100644 index 000000000000..e225f0888a10 --- /dev/null +++ b/packages/babel-parser/test/fixtures/es2017/async-functions/35/output.json @@ -0,0 +1,67 @@ +{ + "type": "File", + "start":0,"end":29,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":29}}, + "errors": [ + "SyntaxError: Invalid shorthand property initializer. (1:20)" + ], + "program": { + "type": "Program", + "start":0,"end":29,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":29}}, + "sourceType": "script", + "interpreter": null, + "body": [ + { + "type": "VariableDeclaration", + "start":0,"end":29,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":29}}, + "declarations": [ + { + "type": "VariableDeclarator", + "start":6,"end":28,"loc":{"start":{"line":1,"column":6},"end":{"line":1,"column":28}}, + "id": { + "type": "Identifier", + "start":6,"end":9,"loc":{"start":{"line":1,"column":6},"end":{"line":1,"column":9},"identifierName":"foo"}, + "name": "foo" + }, + "init": { + "type": "ObjectExpression", + "start":12,"end":28,"loc":{"start":{"line":1,"column":12},"end":{"line":1,"column":28}}, + "properties": [ + { + "type": "ObjectProperty", + "start":14,"end":26,"loc":{"start":{"line":1,"column":14},"end":{"line":1,"column":26}}, + "method": false, + "key": { + "type": "Identifier", + "start":14,"end":19,"loc":{"start":{"line":1,"column":14},"end":{"line":1,"column":19},"identifierName":"async"}, + "name": "async" + }, + "computed": false, + "shorthand": true, + "value": { + "type": "AssignmentPattern", + "start":14,"end":26,"loc":{"start":{"line":1,"column":14},"end":{"line":1,"column":26}}, + "left": { + "type": "Identifier", + "start":14,"end":19,"loc":{"start":{"line":1,"column":14},"end":{"line":1,"column":19},"identifierName":"async"}, + "name": "async" + }, + "right": { + "type": "BooleanLiteral", + "start":22,"end":26,"loc":{"start":{"line":1,"column":22},"end":{"line":1,"column":26}}, + "value": true + } + }, + "extra": { + "shorthand": true + } + } + ] + } + } + ], + "kind": "const" + } + ], + "directives": [] + } +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/es2017/async-functions/36/options.json b/packages/babel-parser/test/fixtures/es2017/async-functions/36/options.json deleted file mode 100644 index 3e7adc2e54dd..000000000000 --- a/packages/babel-parser/test/fixtures/es2017/async-functions/36/options.json +++ /dev/null @@ -1,3 +0,0 @@ -{ - "throws": "Unexpected token (1:21)" -} diff --git a/packages/babel-parser/test/fixtures/es2017/async-functions/36/output.json b/packages/babel-parser/test/fixtures/es2017/async-functions/36/output.json new file mode 100644 index 000000000000..63d0075028cb --- /dev/null +++ b/packages/babel-parser/test/fixtures/es2017/async-functions/36/output.json @@ -0,0 +1,71 @@ +{ + "type": "File", + "start":0,"end":31,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":31}}, + "errors": [ + "SyntaxError: Invalid shorthand property initializer. (1:21)" + ], + "program": { + "type": "Program", + "start":0,"end":31,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":31}}, + "sourceType": "script", + "interpreter": null, + "body": [ + { + "type": "VariableDeclaration", + "start":0,"end":31,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":31}}, + "declarations": [ + { + "type": "VariableDeclarator", + "start":6,"end":30,"loc":{"start":{"line":1,"column":6},"end":{"line":1,"column":30}}, + "id": { + "type": "Identifier", + "start":6,"end":9,"loc":{"start":{"line":1,"column":6},"end":{"line":1,"column":9},"identifierName":"foo"}, + "name": "foo" + }, + "init": { + "type": "ObjectExpression", + "start":13,"end":29,"loc":{"start":{"line":1,"column":13},"end":{"line":1,"column":29}}, + "properties": [ + { + "type": "ObjectProperty", + "start":15,"end":27,"loc":{"start":{"line":1,"column":15},"end":{"line":1,"column":27}}, + "method": false, + "key": { + "type": "Identifier", + "start":15,"end":20,"loc":{"start":{"line":1,"column":15},"end":{"line":1,"column":20},"identifierName":"async"}, + "name": "async" + }, + "computed": false, + "shorthand": true, + "value": { + "type": "AssignmentPattern", + "start":15,"end":27,"loc":{"start":{"line":1,"column":15},"end":{"line":1,"column":27}}, + "left": { + "type": "Identifier", + "start":15,"end":20,"loc":{"start":{"line":1,"column":15},"end":{"line":1,"column":20},"identifierName":"async"}, + "name": "async" + }, + "right": { + "type": "BooleanLiteral", + "start":23,"end":27,"loc":{"start":{"line":1,"column":23},"end":{"line":1,"column":27}}, + "value": true + } + }, + "extra": { + "shorthand": true + } + } + ], + "extra": { + "parenthesized": true, + "parenStart": 12 + } + } + } + ], + "kind": "const" + } + ], + "directives": [] + } +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/esprima/es2015-destructuring-assignment/invalid-cover-grammar/options.json b/packages/babel-parser/test/fixtures/esprima/es2015-destructuring-assignment/invalid-cover-grammar/options.json deleted file mode 100644 index a015cd4108e6..000000000000 --- a/packages/babel-parser/test/fixtures/esprima/es2015-destructuring-assignment/invalid-cover-grammar/options.json +++ /dev/null @@ -1,3 +0,0 @@ -{ - "throws": "Unexpected token (1:22)" -} diff --git a/packages/babel-parser/test/fixtures/esprima/es2015-destructuring-assignment/invalid-cover-grammar/output.json b/packages/babel-parser/test/fixtures/esprima/es2015-destructuring-assignment/invalid-cover-grammar/output.json new file mode 100644 index 000000000000..c9f73b8a8484 --- /dev/null +++ b/packages/babel-parser/test/fixtures/esprima/es2015-destructuring-assignment/invalid-cover-grammar/output.json @@ -0,0 +1,175 @@ +{ + "type": "File", + "start":0,"end":45,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":45}}, + "errors": [ + "SyntaxError: Invalid shorthand property initializer. (1:22)" + ], + "program": { + "type": "Program", + "start":0,"end":45,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":45}}, + "sourceType": "script", + "interpreter": null, + "body": [ + { + "type": "ExpressionStatement", + "start":0,"end":45,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":45}}, + "expression": { + "type": "ArrayExpression", + "start":0,"end":45,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":45}}, + "elements": [ + { + "type": "ArrayExpression", + "start":1,"end":44,"loc":{"start":{"line":1,"column":1},"end":{"line":1,"column":44}}, + "elements": [ + { + "type": "ArrayExpression", + "start":2,"end":43,"loc":{"start":{"line":1,"column":2},"end":{"line":1,"column":43}}, + "elements": [ + { + "type": "ArrayExpression", + "start":3,"end":42,"loc":{"start":{"line":1,"column":3},"end":{"line":1,"column":42}}, + "elements": [ + { + "type": "ArrayExpression", + "start":4,"end":41,"loc":{"start":{"line":1,"column":4},"end":{"line":1,"column":41}}, + "elements": [ + { + "type": "ArrayExpression", + "start":5,"end":40,"loc":{"start":{"line":1,"column":5},"end":{"line":1,"column":40}}, + "elements": [ + { + "type": "ArrayExpression", + "start":6,"end":39,"loc":{"start":{"line":1,"column":6},"end":{"line":1,"column":39}}, + "elements": [ + { + "type": "ArrayExpression", + "start":7,"end":38,"loc":{"start":{"line":1,"column":7},"end":{"line":1,"column":38}}, + "elements": [ + { + "type": "ArrayExpression", + "start":8,"end":37,"loc":{"start":{"line":1,"column":8},"end":{"line":1,"column":37}}, + "elements": [ + { + "type": "ArrayExpression", + "start":9,"end":36,"loc":{"start":{"line":1,"column":9},"end":{"line":1,"column":36}}, + "elements": [ + { + "type": "ArrayExpression", + "start":10,"end":35,"loc":{"start":{"line":1,"column":10},"end":{"line":1,"column":35}}, + "elements": [ + { + "type": "ArrayExpression", + "start":11,"end":34,"loc":{"start":{"line":1,"column":11},"end":{"line":1,"column":34}}, + "elements": [ + { + "type": "ArrayExpression", + "start":12,"end":33,"loc":{"start":{"line":1,"column":12},"end":{"line":1,"column":33}}, + "elements": [ + { + "type": "ArrayExpression", + "start":13,"end":32,"loc":{"start":{"line":1,"column":13},"end":{"line":1,"column":32}}, + "elements": [ + { + "type": "ArrayExpression", + "start":14,"end":31,"loc":{"start":{"line":1,"column":14},"end":{"line":1,"column":31}}, + "elements": [ + { + "type": "ArrayExpression", + "start":15,"end":30,"loc":{"start":{"line":1,"column":15},"end":{"line":1,"column":30}}, + "elements": [ + { + "type": "ArrayExpression", + "start":16,"end":29,"loc":{"start":{"line":1,"column":16},"end":{"line":1,"column":29}}, + "elements": [ + { + "type": "ArrayExpression", + "start":17,"end":28,"loc":{"start":{"line":1,"column":17},"end":{"line":1,"column":28}}, + "elements": [ + { + "type": "ArrayExpression", + "start":18,"end":27,"loc":{"start":{"line":1,"column":18},"end":{"line":1,"column":27}}, + "elements": [ + { + "type": "ArrayExpression", + "start":19,"end":26,"loc":{"start":{"line":1,"column":19},"end":{"line":1,"column":26}}, + "elements": [ + { + "type": "ObjectExpression", + "start":20,"end":25,"loc":{"start":{"line":1,"column":20},"end":{"line":1,"column":25}}, + "properties": [ + { + "type": "ObjectProperty", + "start":21,"end":24,"loc":{"start":{"line":1,"column":21},"end":{"line":1,"column":24}}, + "method": false, + "key": { + "type": "Identifier", + "start":21,"end":22,"loc":{"start":{"line":1,"column":21},"end":{"line":1,"column":22},"identifierName":"a"}, + "name": "a" + }, + "computed": false, + "shorthand": true, + "value": { + "type": "AssignmentPattern", + "start":21,"end":24,"loc":{"start":{"line":1,"column":21},"end":{"line":1,"column":24}}, + "left": { + "type": "Identifier", + "start":21,"end":22,"loc":{"start":{"line":1,"column":21},"end":{"line":1,"column":22},"identifierName":"a"}, + "name": "a" + }, + "right": { + "type": "Identifier", + "start":23,"end":24,"loc":{"start":{"line":1,"column":23},"end":{"line":1,"column":24},"identifierName":"b"}, + "name": "b" + } + }, + "extra": { + "shorthand": true + } + } + ] + } + ] + } + ] + } + ] + } + ] + } + ] + } + ] + } + ] + } + ] + } + ] + } + ] + } + ] + } + ] + } + ] + } + ] + } + ] + } + ] + } + ] + } + ] + } + ] + } + ] + } + } + ], + "directives": [] + } +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/experimental/record-and-tuple/invalid-property-initializer/input.js b/packages/babel-parser/test/fixtures/experimental/record-and-tuple/invalid-property-initializer/input.js new file mode 100644 index 000000000000..5c2964e9a89b --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/record-and-tuple/invalid-property-initializer/input.js @@ -0,0 +1 @@ +#{ x = 1 } diff --git a/packages/babel-parser/test/fixtures/experimental/record-and-tuple/invalid-property-initializer/options.json b/packages/babel-parser/test/fixtures/experimental/record-and-tuple/invalid-property-initializer/options.json new file mode 100644 index 000000000000..703c537be360 --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/record-and-tuple/invalid-property-initializer/options.json @@ -0,0 +1,3 @@ +{ + "plugins": [["recordAndTuple", { "syntaxType": "hash" }]] +} diff --git a/packages/babel-parser/test/fixtures/experimental/record-and-tuple/invalid-property-initializer/output.json b/packages/babel-parser/test/fixtures/experimental/record-and-tuple/invalid-property-initializer/output.json new file mode 100644 index 000000000000..b6806148695d --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/record-and-tuple/invalid-property-initializer/output.json @@ -0,0 +1,59 @@ +{ + "type": "File", + "start":0,"end":10,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":10}}, + "errors": [ + "SyntaxError: Invalid shorthand property initializer. (1:5)" + ], + "program": { + "type": "Program", + "start":0,"end":10,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":10}}, + "sourceType": "script", + "interpreter": null, + "body": [ + { + "type": "ExpressionStatement", + "start":0,"end":10,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":10}}, + "expression": { + "type": "RecordExpression", + "start":0,"end":10,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":10}}, + "properties": [ + { + "type": "ObjectProperty", + "start":3,"end":8,"loc":{"start":{"line":1,"column":3},"end":{"line":1,"column":8}}, + "method": false, + "key": { + "type": "Identifier", + "start":3,"end":4,"loc":{"start":{"line":1,"column":3},"end":{"line":1,"column":4},"identifierName":"x"}, + "name": "x" + }, + "computed": false, + "shorthand": true, + "value": { + "type": "AssignmentPattern", + "start":5,"end":8,"loc":{"start":{"line":1,"column":5},"end":{"line":1,"column":8}}, + "left": { + "type": "Identifier", + "start":3,"end":4,"loc":{"start":{"line":1,"column":3},"end":{"line":1,"column":4},"identifierName":"x"}, + "name": "x" + }, + "right": { + "type": "NumericLiteral", + "start":7,"end":8,"loc":{"start":{"line":1,"column":7},"end":{"line":1,"column":8}}, + "extra": { + "rawValue": 1, + "raw": "1" + }, + "value": 1 + } + }, + "extra": { + "shorthand": true + } + } + ] + } + } + ], + "directives": [] + } +} \ No newline at end of file