diff --git a/packages/babel-parser/src/parser/expression.js b/packages/babel-parser/src/parser/expression.js index 5ce81a443b86..e0dc1b512f33 100644 --- a/packages/babel-parser/src/parser/expression.js +++ b/packages/babel-parser/src/parser/expression.js @@ -1505,12 +1505,12 @@ export default class ExpressionParser extends LValParser { this.state.start, "Stage 2 decorators disallow object literal property decorators", ); - } else { - // we needn't check if decorators (stage 0) plugin is enabled since it's checked by - // the call to this.parseDecorator - while (this.match(tt.at)) { - decorators.push(this.parseDecorator()); - } + } + + // we needn't check if decorators (stage 0) plugin is enabled since it's checked by + // the call to this.parseDecorator + while (this.match(tt.at)) { + decorators.push(this.parseDecorator()); } } diff --git a/packages/babel-parser/test/fixtures/experimental/decorators-2/no-object-methods/options.json b/packages/babel-parser/test/fixtures/experimental/decorators-2/no-object-methods/options.json index 302bc76824f7..69639859c25e 100644 --- a/packages/babel-parser/test/fixtures/experimental/decorators-2/no-object-methods/options.json +++ b/packages/babel-parser/test/fixtures/experimental/decorators-2/no-object-methods/options.json @@ -6,6 +6,5 @@ "decoratorsBeforeExport": false } ] - ], - "throws": "Unexpected token (2:2)" + ] } \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/experimental/decorators-2/no-object-methods/output.json b/packages/babel-parser/test/fixtures/experimental/decorators-2/no-object-methods/output.json new file mode 100644 index 000000000000..e50713954be0 --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/decorators-2/no-object-methods/output.json @@ -0,0 +1,195 @@ +{ + "type": "File", + "start": 0, + "end": 32, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 5, + "column": 1 + } + }, + "errors": [ + "SyntaxError: Stage 2 decorators disallow object literal property decorators (2:2)" + ], + "program": { + "type": "Program", + "start": 0, + "end": 32, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 5, + "column": 1 + } + }, + "sourceType": "script", + "interpreter": null, + "body": [ + { + "type": "VariableDeclaration", + "start": 0, + "end": 32, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 5, + "column": 1 + } + }, + "declarations": [ + { + "type": "VariableDeclarator", + "start": 4, + "end": 32, + "loc": { + "start": { + "line": 1, + "column": 4 + }, + "end": { + "line": 5, + "column": 1 + } + }, + "id": { + "type": "Identifier", + "start": 4, + "end": 5, + "loc": { + "start": { + "line": 1, + "column": 4 + }, + "end": { + "line": 1, + "column": 5 + }, + "identifierName": "o" + }, + "name": "o" + }, + "init": { + "type": "ObjectExpression", + "start": 8, + "end": 32, + "loc": { + "start": { + "line": 1, + "column": 8 + }, + "end": { + "line": 5, + "column": 1 + } + }, + "properties": [ + { + "type": "ObjectMethod", + "start": 19, + "end": 30, + "loc": { + "start": { + "line": 3, + "column": 2 + }, + "end": { + "line": 4, + "column": 3 + } + }, + "decorators": [ + { + "type": "Decorator", + "start": 12, + "end": 16, + "loc": { + "start": { + "line": 2, + "column": 2 + }, + "end": { + "line": 2, + "column": 6 + } + }, + "expression": { + "type": "Identifier", + "start": 13, + "end": 16, + "loc": { + "start": { + "line": 2, + "column": 3 + }, + "end": { + "line": 2, + "column": 6 + }, + "identifierName": "baz" + }, + "name": "baz" + } + } + ], + "method": true, + "key": { + "type": "Identifier", + "start": 19, + "end": 22, + "loc": { + "start": { + "line": 3, + "column": 2 + }, + "end": { + "line": 3, + "column": 5 + }, + "identifierName": "foo" + }, + "name": "foo" + }, + "computed": false, + "kind": "method", + "id": null, + "generator": false, + "async": false, + "params": [], + "body": { + "type": "BlockStatement", + "start": 25, + "end": 30, + "loc": { + "start": { + "line": 3, + "column": 8 + }, + "end": { + "line": 4, + "column": 3 + } + }, + "body": [], + "directives": [] + } + } + ] + } + } + ], + "kind": "var" + } + ], + "directives": [] + } +} \ No newline at end of file