diff --git a/src/parser/expression.js b/src/parser/expression.js index 44a9051a7e..b186920805 100644 --- a/src/parser/expression.js +++ b/src/parser/expression.js @@ -847,8 +847,16 @@ export default class ExpressionParser extends LValParser { if (this.eat(tt.braceR)) break; } - while (this.match(tt.at)) { - decorators.push(this.parseDecorator()); + if (this.match(tt.at)) { + if (this.hasPlugin("decorators-stage-2")) { + this.raise(this.state.start, "decorators-stage-2 disallows 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()); + } + } } let prop = this.startNode(), isGenerator = false, isAsync = false, startPos, startLoc; diff --git a/src/parser/lval.js b/src/parser/lval.js index d3fcd02900..8e0f153cf7 100644 --- a/src/parser/lval.js +++ b/src/parser/lval.js @@ -187,6 +187,9 @@ export default class LValParser extends NodeUtils { break; } else { const decorators = []; + if (this.match(tt.at) && this.hasPlugin("decorators-stage-2")) { + this.raise(this.state.start, "Stage 2 decorators cannot be used to decorate parameters"); + } while (this.match(tt.at)) { decorators.push(this.parseDecorator()); } diff --git a/src/parser/statement.js b/src/parser/statement.js index 7731c7a9f3..361b251a98 100644 --- a/src/parser/statement.js +++ b/src/parser/statement.js @@ -709,6 +709,10 @@ export default class StatementParser extends ExpressionParser { } this.parseClassMember(classBody, member, state); + + if (this.hasPlugin("decorators-stage-2") && member.kind != "method" && member.decorators && member.decorators.length > 0) { + this.raise(member.start, "Stage 2 decorators may only be used with a class or a class method"); + } } if (decorators.length) { @@ -776,6 +780,7 @@ export default class StatementParser extends ExpressionParser { if (!methodOrProp.computed && methodOrProp.static && (methodOrProp.key.name === "prototype" || methodOrProp.key.value === "prototype")) { this.raise(methodOrProp.key.start, "Classes may not have static property named prototype"); } + if (this.isClassMethod()) { // a normal method if (this.isNonstaticConstructor(method)) { diff --git a/test/fixtures/experimental/decorators-stage-2/class-decorator-call-expr/actual.js b/test/fixtures/experimental/decorators-stage-2/class-decorator-call-expr/actual.js new file mode 100644 index 0000000000..8f69136200 --- /dev/null +++ b/test/fixtures/experimental/decorators-stage-2/class-decorator-call-expr/actual.js @@ -0,0 +1,2 @@ +@foo('bar') +class Foo {} diff --git a/test/fixtures/experimental/decorators-stage-2/class-decorator-call-expr/expected.json b/test/fixtures/experimental/decorators-stage-2/class-decorator-call-expr/expected.json new file mode 100644 index 0000000000..291ef173cc --- /dev/null +++ b/test/fixtures/experimental/decorators-stage-2/class-decorator-call-expr/expected.json @@ -0,0 +1,154 @@ +{ + "type": "File", + "start": 0, + "end": 24, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 2, + "column": 12 + } + }, + "program": { + "type": "Program", + "start": 0, + "end": 24, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 2, + "column": 12 + } + }, + "sourceType": "script", + "body": [ + { + "type": "ClassDeclaration", + "start": 12, + "end": 24, + "loc": { + "start": { + "line": 2, + "column": 0 + }, + "end": { + "line": 2, + "column": 12 + } + }, + "decorators": [ + { + "type": "Decorator", + "start": 0, + "end": 11, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 11 + } + }, + "expression": { + "type": "CallExpression", + "start": 1, + "end": 11, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 11 + } + }, + "callee": { + "type": "Identifier", + "start": 1, + "end": 4, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 4 + }, + "identifierName": "foo" + }, + "name": "foo" + }, + "arguments": [ + { + "type": "StringLiteral", + "start": 5, + "end": 10, + "loc": { + "start": { + "line": 1, + "column": 5 + }, + "end": { + "line": 1, + "column": 10 + } + }, + "extra": { + "rawValue": "bar", + "raw": "'bar'" + }, + "value": "bar" + } + ] + } + } + ], + "id": { + "type": "Identifier", + "start": 18, + "end": 21, + "loc": { + "start": { + "line": 2, + "column": 6 + }, + "end": { + "line": 2, + "column": 9 + }, + "identifierName": "Foo" + }, + "name": "Foo" + }, + "superClass": null, + "body": { + "type": "ClassBody", + "start": 22, + "end": 24, + "loc": { + "start": { + "line": 2, + "column": 10 + }, + "end": { + "line": 2, + "column": 12 + } + }, + "body": [] + } + } + ], + "directives": [] + } +} \ No newline at end of file diff --git a/test/fixtures/experimental/decorators-stage-2/class-decorator/actual.js b/test/fixtures/experimental/decorators-stage-2/class-decorator/actual.js new file mode 100644 index 0000000000..b1d1c0dd75 --- /dev/null +++ b/test/fixtures/experimental/decorators-stage-2/class-decorator/actual.js @@ -0,0 +1,4 @@ +@abc +class Foo { + +} diff --git a/test/fixtures/experimental/decorators-stage-2/class-decorator/expected.json b/test/fixtures/experimental/decorators-stage-2/class-decorator/expected.json new file mode 100644 index 0000000000..8299bdd639 --- /dev/null +++ b/test/fixtures/experimental/decorators-stage-2/class-decorator/expected.json @@ -0,0 +1,117 @@ +{ + "type": "File", + "start": 0, + "end": 19, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 4, + "column": 1 + } + }, + "program": { + "type": "Program", + "start": 0, + "end": 19, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 4, + "column": 1 + } + }, + "sourceType": "script", + "body": [ + { + "type": "ClassDeclaration", + "start": 5, + "end": 19, + "loc": { + "start": { + "line": 2, + "column": 0 + }, + "end": { + "line": 4, + "column": 1 + } + }, + "decorators": [ + { + "type": "Decorator", + "start": 0, + "end": 4, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 4 + } + }, + "expression": { + "type": "Identifier", + "start": 1, + "end": 4, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 4 + }, + "identifierName": "abc" + }, + "name": "abc" + } + } + ], + "id": { + "type": "Identifier", + "start": 11, + "end": 14, + "loc": { + "start": { + "line": 2, + "column": 6 + }, + "end": { + "line": 2, + "column": 9 + }, + "identifierName": "Foo" + }, + "name": "Foo" + }, + "superClass": null, + "body": { + "type": "ClassBody", + "start": 15, + "end": 19, + "loc": { + "start": { + "line": 2, + "column": 10 + }, + "end": { + "line": 4, + "column": 1 + } + }, + "body": [] + } + } + ], + "directives": [] + } +} \ No newline at end of file diff --git a/test/fixtures/experimental/decorators-stage-2/class-method-parameter/actual.js b/test/fixtures/experimental/decorators-stage-2/class-method-parameter/actual.js new file mode 100644 index 0000000000..6ebf34c91e --- /dev/null +++ b/test/fixtures/experimental/decorators-stage-2/class-method-parameter/actual.js @@ -0,0 +1,3 @@ +class Foo { + constructor(@foo x) {} +} diff --git a/test/fixtures/experimental/decorators-stage-2/class-method-parameter/options.json b/test/fixtures/experimental/decorators-stage-2/class-method-parameter/options.json new file mode 100644 index 0000000000..7b4e6dc626 --- /dev/null +++ b/test/fixtures/experimental/decorators-stage-2/class-method-parameter/options.json @@ -0,0 +1,3 @@ +{ + "throws": "Stage 2 decorators cannot be used to decorate parameters (2:14)" +} diff --git a/test/fixtures/experimental/decorators-stage-2/computed-member-expr-on-prop/actual.js b/test/fixtures/experimental/decorators-stage-2/computed-member-expr-on-prop/actual.js new file mode 100644 index 0000000000..a7c918a617 --- /dev/null +++ b/test/fixtures/experimental/decorators-stage-2/computed-member-expr-on-prop/actual.js @@ -0,0 +1,3 @@ +class Foo { + @foo[bar] a = 1; +} diff --git a/test/fixtures/experimental/decorators-stage-2/computed-member-expr-on-prop/options.json b/test/fixtures/experimental/decorators-stage-2/computed-member-expr-on-prop/options.json new file mode 100644 index 0000000000..d1e493e091 --- /dev/null +++ b/test/fixtures/experimental/decorators-stage-2/computed-member-expr-on-prop/options.json @@ -0,0 +1,4 @@ +{ + "plugins": ["decorators-stage-2", "classProperties"], + "throws": "Unexpected token (2:12)" +} diff --git a/test/fixtures/experimental/decorators-stage-2/computed-member-expression/actual.js b/test/fixtures/experimental/decorators-stage-2/computed-member-expression/actual.js new file mode 100644 index 0000000000..f261291097 --- /dev/null +++ b/test/fixtures/experimental/decorators-stage-2/computed-member-expression/actual.js @@ -0,0 +1,6 @@ +class Foo { + @bar[bizz] + abc() { + + } +} diff --git a/test/fixtures/experimental/decorators-stage-2/computed-member-expression/options.json b/test/fixtures/experimental/decorators-stage-2/computed-member-expression/options.json new file mode 100644 index 0000000000..a4c63d917c --- /dev/null +++ b/test/fixtures/experimental/decorators-stage-2/computed-member-expression/options.json @@ -0,0 +1,4 @@ +{ + "plugins": ["decorators-stage-2", "classProperties"], + "throws": "Stage 2 decorators may only be used with a class or a class method (2:6)" +} diff --git a/test/fixtures/experimental/decorators-stage-2/export-decorators-on-class/actual.js b/test/fixtures/experimental/decorators-stage-2/export-decorators-on-class/actual.js new file mode 100644 index 0000000000..51804c6056 --- /dev/null +++ b/test/fixtures/experimental/decorators-stage-2/export-decorators-on-class/actual.js @@ -0,0 +1,2 @@ +@foo +export default class {} \ No newline at end of file diff --git a/test/fixtures/experimental/decorators-stage-2/export-decorators-on-class/expected.json b/test/fixtures/experimental/decorators-stage-2/export-decorators-on-class/expected.json new file mode 100644 index 0000000000..6933de60e7 --- /dev/null +++ b/test/fixtures/experimental/decorators-stage-2/export-decorators-on-class/expected.json @@ -0,0 +1,116 @@ +{ + "type": "File", + "start": 0, + "end": 28, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 2, + "column": 23 + } + }, + "program": { + "type": "Program", + "start": 0, + "end": 28, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 2, + "column": 23 + } + }, + "sourceType": "module", + "body": [ + { + "type": "ExportDefaultDeclaration", + "start": 5, + "end": 28, + "loc": { + "start": { + "line": 2, + "column": 0 + }, + "end": { + "line": 2, + "column": 23 + } + }, + "declaration": { + "type": "ClassDeclaration", + "start": 20, + "end": 28, + "loc": { + "start": { + "line": 2, + "column": 15 + }, + "end": { + "line": 2, + "column": 23 + } + }, + "decorators": [ + { + "type": "Decorator", + "start": 0, + "end": 4, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 4 + } + }, + "expression": { + "type": "Identifier", + "start": 1, + "end": 4, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 4 + }, + "identifierName": "foo" + }, + "name": "foo" + } + } + ], + "id": null, + "superClass": null, + "body": { + "type": "ClassBody", + "start": 26, + "end": 28, + "loc": { + "start": { + "line": 2, + "column": 21 + }, + "end": { + "line": 2, + "column": 23 + } + }, + "body": [] + } + } + } + ], + "directives": [] + } +} \ No newline at end of file diff --git a/test/fixtures/experimental/decorators-stage-2/export-decorators-on-class/options.json b/test/fixtures/experimental/decorators-stage-2/export-decorators-on-class/options.json new file mode 100644 index 0000000000..2104ca4328 --- /dev/null +++ b/test/fixtures/experimental/decorators-stage-2/export-decorators-on-class/options.json @@ -0,0 +1,3 @@ +{ + "sourceType": "module" +} diff --git a/test/fixtures/experimental/decorators-stage-2/export-default-with-nested-class/actual.js b/test/fixtures/experimental/decorators-stage-2/export-default-with-nested-class/actual.js new file mode 100644 index 0000000000..d0d8d6c4ec --- /dev/null +++ b/test/fixtures/experimental/decorators-stage-2/export-default-with-nested-class/actual.js @@ -0,0 +1,7 @@ +@ParentDecorator +export default class ParentClass { + makeNestedClass() { + class NestedClass { + } + } +} diff --git a/test/fixtures/experimental/decorators-stage-2/export-default-with-nested-class/expected.json b/test/fixtures/experimental/decorators-stage-2/export-default-with-nested-class/expected.json new file mode 100644 index 0000000000..2c797decfc --- /dev/null +++ b/test/fixtures/experimental/decorators-stage-2/export-default-with-nested-class/expected.json @@ -0,0 +1,240 @@ +{ + "type": "File", + "start": 0, + "end": 109, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 7, + "column": 1 + } + }, + "program": { + "type": "Program", + "start": 0, + "end": 109, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 7, + "column": 1 + } + }, + "sourceType": "module", + "body": [ + { + "type": "ExportDefaultDeclaration", + "start": 17, + "end": 109, + "loc": { + "start": { + "line": 2, + "column": 0 + }, + "end": { + "line": 7, + "column": 1 + } + }, + "declaration": { + "type": "ClassDeclaration", + "start": 32, + "end": 109, + "loc": { + "start": { + "line": 2, + "column": 15 + }, + "end": { + "line": 7, + "column": 1 + } + }, + "decorators": [ + { + "type": "Decorator", + "start": 0, + "end": 16, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 16 + } + }, + "expression": { + "type": "Identifier", + "start": 1, + "end": 16, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 16 + }, + "identifierName": "ParentDecorator" + }, + "name": "ParentDecorator" + } + } + ], + "id": { + "type": "Identifier", + "start": 38, + "end": 49, + "loc": { + "start": { + "line": 2, + "column": 21 + }, + "end": { + "line": 2, + "column": 32 + }, + "identifierName": "ParentClass" + }, + "name": "ParentClass" + }, + "superClass": null, + "body": { + "type": "ClassBody", + "start": 50, + "end": 109, + "loc": { + "start": { + "line": 2, + "column": 33 + }, + "end": { + "line": 7, + "column": 1 + } + }, + "body": [ + { + "type": "ClassMethod", + "start": 54, + "end": 107, + "loc": { + "start": { + "line": 3, + "column": 2 + }, + "end": { + "line": 6, + "column": 3 + } + }, + "static": false, + "computed": false, + "key": { + "type": "Identifier", + "start": 54, + "end": 69, + "loc": { + "start": { + "line": 3, + "column": 2 + }, + "end": { + "line": 3, + "column": 17 + }, + "identifierName": "makeNestedClass" + }, + "name": "makeNestedClass" + }, + "kind": "method", + "id": null, + "generator": false, + "expression": false, + "async": false, + "params": [], + "body": { + "type": "BlockStatement", + "start": 72, + "end": 107, + "loc": { + "start": { + "line": 3, + "column": 20 + }, + "end": { + "line": 6, + "column": 3 + } + }, + "body": [ + { + "type": "ClassDeclaration", + "start": 78, + "end": 103, + "loc": { + "start": { + "line": 4, + "column": 4 + }, + "end": { + "line": 5, + "column": 5 + } + }, + "id": { + "type": "Identifier", + "start": 84, + "end": 95, + "loc": { + "start": { + "line": 4, + "column": 10 + }, + "end": { + "line": 4, + "column": 21 + }, + "identifierName": "NestedClass" + }, + "name": "NestedClass" + }, + "superClass": null, + "body": { + "type": "ClassBody", + "start": 96, + "end": 103, + "loc": { + "start": { + "line": 4, + "column": 22 + }, + "end": { + "line": 5, + "column": 5 + } + }, + "body": [] + } + } + ], + "directives": [] + } + } + ] + } + } + } + ], + "directives": [] + } +} \ No newline at end of file diff --git a/test/fixtures/experimental/decorators-stage-2/export-default-with-nested-class/options.json b/test/fixtures/experimental/decorators-stage-2/export-default-with-nested-class/options.json new file mode 100644 index 0000000000..2104ca4328 --- /dev/null +++ b/test/fixtures/experimental/decorators-stage-2/export-default-with-nested-class/options.json @@ -0,0 +1,3 @@ +{ + "sourceType": "module" +} diff --git a/test/fixtures/experimental/decorators-stage-2/function-parameters/actual.js b/test/fixtures/experimental/decorators-stage-2/function-parameters/actual.js new file mode 100644 index 0000000000..857c046452 --- /dev/null +++ b/test/fixtures/experimental/decorators-stage-2/function-parameters/actual.js @@ -0,0 +1 @@ +function func(@foo x) {} diff --git a/test/fixtures/experimental/decorators-stage-2/function-parameters/options.json b/test/fixtures/experimental/decorators-stage-2/function-parameters/options.json new file mode 100644 index 0000000000..6637fc7f83 --- /dev/null +++ b/test/fixtures/experimental/decorators-stage-2/function-parameters/options.json @@ -0,0 +1,3 @@ +{ + "throws": "Stage 2 decorators cannot be used to decorate parameters (1:14)" +} diff --git a/test/fixtures/experimental/decorators-stage-2/no-constructor-decorators/actual.js b/test/fixtures/experimental/decorators-stage-2/no-constructor-decorators/actual.js new file mode 100644 index 0000000000..4387084bbf --- /dev/null +++ b/test/fixtures/experimental/decorators-stage-2/no-constructor-decorators/actual.js @@ -0,0 +1,4 @@ +class Foo { + @abc + constructor(){} +} diff --git a/test/fixtures/experimental/decorators-stage-2/no-constructor-decorators/options.json b/test/fixtures/experimental/decorators-stage-2/no-constructor-decorators/options.json new file mode 100644 index 0000000000..c0baef5996 --- /dev/null +++ b/test/fixtures/experimental/decorators-stage-2/no-constructor-decorators/options.json @@ -0,0 +1,3 @@ +{ + "throws": "You can't attach decorators to a class constructor (3:2)" +} diff --git a/test/fixtures/experimental/decorators-stage-2/no-export-decorators-without-class/actual.js b/test/fixtures/experimental/decorators-stage-2/no-export-decorators-without-class/actual.js new file mode 100644 index 0000000000..c5a55d643f --- /dev/null +++ b/test/fixtures/experimental/decorators-stage-2/no-export-decorators-without-class/actual.js @@ -0,0 +1,2 @@ +@foo +export default function f(){}; \ No newline at end of file diff --git a/test/fixtures/experimental/decorators-stage-2/no-export-decorators-without-class/options.json b/test/fixtures/experimental/decorators-stage-2/no-export-decorators-without-class/options.json new file mode 100644 index 0000000000..61c2c23daa --- /dev/null +++ b/test/fixtures/experimental/decorators-stage-2/no-export-decorators-without-class/options.json @@ -0,0 +1,4 @@ +{ + "throws": "You can only use decorators on an export when exporting a class (2:0)", + "sourceType": "module" +} diff --git a/test/fixtures/experimental/decorators-stage-2/no-export-decorators/actual.js b/test/fixtures/experimental/decorators-stage-2/no-export-decorators/actual.js new file mode 100644 index 0000000000..4630d555a4 --- /dev/null +++ b/test/fixtures/experimental/decorators-stage-2/no-export-decorators/actual.js @@ -0,0 +1,2 @@ +@foo +export default 0; \ No newline at end of file diff --git a/test/fixtures/experimental/decorators-stage-2/no-export-decorators/options.json b/test/fixtures/experimental/decorators-stage-2/no-export-decorators/options.json new file mode 100644 index 0000000000..61c2c23daa --- /dev/null +++ b/test/fixtures/experimental/decorators-stage-2/no-export-decorators/options.json @@ -0,0 +1,4 @@ +{ + "throws": "You can only use decorators on an export when exporting a class (2:0)", + "sourceType": "module" +} diff --git a/test/fixtures/experimental/decorators-stage-2/no-semi/actual.js b/test/fixtures/experimental/decorators-stage-2/no-semi/actual.js new file mode 100644 index 0000000000..6138e9c6f9 --- /dev/null +++ b/test/fixtures/experimental/decorators-stage-2/no-semi/actual.js @@ -0,0 +1,4 @@ +class A { + @a; + m(){} +} diff --git a/test/fixtures/experimental/decorators-stage-2/no-semi/options.json b/test/fixtures/experimental/decorators-stage-2/no-semi/options.json new file mode 100644 index 0000000000..ffac21b695 --- /dev/null +++ b/test/fixtures/experimental/decorators-stage-2/no-semi/options.json @@ -0,0 +1,3 @@ +{ + "throws": "Decorators must not be followed by a semicolon (2:5)" +} diff --git a/test/fixtures/experimental/decorators-stage-2/object-method-parameter/actual.js b/test/fixtures/experimental/decorators-stage-2/object-method-parameter/actual.js new file mode 100644 index 0000000000..a1aed846a9 --- /dev/null +++ b/test/fixtures/experimental/decorators-stage-2/object-method-parameter/actual.js @@ -0,0 +1,3 @@ +var obj = { + method(@foo x) {} +}; diff --git a/test/fixtures/experimental/decorators-stage-2/object-method-parameter/options.json b/test/fixtures/experimental/decorators-stage-2/object-method-parameter/options.json new file mode 100644 index 0000000000..b173069693 --- /dev/null +++ b/test/fixtures/experimental/decorators-stage-2/object-method-parameter/options.json @@ -0,0 +1,3 @@ +{ + "throws": "Stage 2 decorators cannot be used to decorate parameters (2:9)" +} diff --git a/test/fixtures/experimental/decorators-stage-2/on-computed-name-prop/expected.json b/test/fixtures/experimental/decorators-stage-2/on-computed-name-prop/expected.json deleted file mode 100644 index 718d922864..0000000000 --- a/test/fixtures/experimental/decorators-stage-2/on-computed-name-prop/expected.json +++ /dev/null @@ -1,175 +0,0 @@ -{ - "type": "File", - "start": 0, - "end": 31, - "loc": { - "start": { - "line": 1, - "column": 0 - }, - "end": { - "line": 3, - "column": 1 - } - }, - "program": { - "type": "Program", - "start": 0, - "end": 31, - "loc": { - "start": { - "line": 1, - "column": 0 - }, - "end": { - "line": 3, - "column": 1 - } - }, - "sourceType": "script", - "body": [ - { - "type": "ClassDeclaration", - "start": 0, - "end": 31, - "loc": { - "start": { - "line": 1, - "column": 0 - }, - "end": { - "line": 3, - "column": 1 - } - }, - "id": { - "type": "Identifier", - "start": 6, - "end": 7, - "loc": { - "start": { - "line": 1, - "column": 6 - }, - "end": { - "line": 1, - "column": 7 - }, - "identifierName": "A" - }, - "name": "A" - }, - "superClass": null, - "body": { - "type": "ClassBody", - "start": 8, - "end": 31, - "loc": { - "start": { - "line": 1, - "column": 8 - }, - "end": { - "line": 3, - "column": 1 - } - }, - "body": [ - { - "type": "ClassProperty", - "start": 17, - "end": 29, - "loc": { - "start": { - "line": 2, - "column": 7 - }, - "end": { - "line": 2, - "column": 19 - } - }, - "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": "dec" - }, - "name": "dec" - } - } - ], - "static": false, - "computed": true, - "key": { - "type": "StringLiteral", - "start": 18, - "end": 24, - "loc": { - "start": { - "line": 2, - "column": 8 - }, - "end": { - "line": 2, - "column": 14 - } - }, - "extra": { - "rawValue": "name", - "raw": "'name'" - }, - "value": "name" - }, - "value": { - "type": "NumericLiteral", - "start": 28, - "end": 29, - "loc": { - "start": { - "line": 2, - "column": 18 - }, - "end": { - "line": 2, - "column": 19 - } - }, - "extra": { - "rawValue": 0, - "raw": "0" - }, - "value": 0 - } - } - ] - } - } - ], - "directives": [] - } -} \ No newline at end of file diff --git a/test/fixtures/experimental/decorators-stage-2/on-computed-name-prop/options.json b/test/fixtures/experimental/decorators-stage-2/on-computed-name-prop/options.json index 2974185c0c..481f6730cc 100644 --- a/test/fixtures/experimental/decorators-stage-2/on-computed-name-prop/options.json +++ b/test/fixtures/experimental/decorators-stage-2/on-computed-name-prop/options.json @@ -1,3 +1,4 @@ { - "plugins": ["classProperties", "decorators-stage-2"] + "plugins": ["classProperties", "decorators-stage-2"], + "throws": "Stage 2 decorators may only be used with a class or a class method (2:7)" }