Merge pull request #587 from peey/decorators-stage-2

Decorators Stage 2 Parsing
This commit is contained in:
Henry Zhu 2017-06-22 10:20:08 -04:00 committed by GitHub
commit f976bdd21c
48 changed files with 1572 additions and 4 deletions

View File

@ -47,6 +47,11 @@ const parserClassCache: { [key: string]: Class<Parser> } = {};
/** Get a Parser class with plugins applied. */
function getParserClass(pluginsFromOptions: $ReadOnlyArray<string>): Class<Parser> {
if (pluginsFromOptions.indexOf("decorators") >= 0 && pluginsFromOptions.indexOf("decorators2") >= 0) {
throw new Error("Cannot use decorators and decorators2 plugin together");
}
// Filter out just the plugins that have an actual mixin associated with them.
let pluginList = pluginsFromOptions.filter((p) => p === "estree" || p === "flow" || p === "jsx");

View File

@ -857,8 +857,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("decorators2")) {
this.raise(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());
}
}
}
let prop = this.startNode(), isGenerator = false, isAsync = false, startPos, startLoc;

View File

@ -187,6 +187,9 @@ export default class LValParser extends NodeUtils {
break;
} else {
const decorators = [];
if (this.match(tt.at) && this.hasPlugin("decorators2")) {
this.raise(this.state.start, "Stage 2 decorators cannot be used to decorate parameters");
}
while (this.match(tt.at)) {
decorators.push(this.parseDecorator());
}

View File

@ -152,11 +152,18 @@ export default class StatementParser extends ExpressionParser {
takeDecorators(node: N.HasDecorators): void {
if (this.state.decorators.length) {
node.decorators = this.state.decorators;
if (this.hasPlugin("decorators2")) {
this.resetStartLocationFromNode(node, this.state.decorators[0]);
}
this.state.decorators = [];
}
}
parseDecorators(allowExport?: boolean): void {
if (this.hasPlugin("decorators2")) {
allowExport = false;
}
while (this.match(tt.at)) {
const decorator = this.parseDecorator();
this.state.decorators.push(decorator);
@ -172,12 +179,38 @@ export default class StatementParser extends ExpressionParser {
}
parseDecorator(): N.Decorator {
if (!this.hasPlugin("decorators")) {
if (!(this.hasPlugin("decorators") || this.hasPlugin("decorators2"))) {
this.unexpected();
}
const node = this.startNode();
this.next();
node.expression = this.parseMaybeAssign();
if (this.hasPlugin("decorators2")) {
const startPos = this.state.start;
const startLoc = this.state.startLoc;
let expr = this.parseIdentifier(false);
while (this.eat(tt.dot)) {
const node = this.startNodeAt(startPos, startLoc);
node.object = expr;
node.property = this.parseIdentifier(true);
node.computed = false;
expr = this.finishNode(node, "MemberExpression");
}
if (this.eat(tt.parenL)) {
const node = this.startNodeAt(startPos, startLoc);
node.callee = expr;
node.arguments = this.parseCallExpressionArguments(tt.parenR, false);
expr = this.finishNode(node, "CallExpression");
this.toReferencedList(expr.arguments);
}
node.expression = expr;
} else {
node.expression = this.parseMaybeAssign();
}
return this.finishNode(node, "Decorator");
}
@ -679,10 +712,17 @@ export default class StatementParser extends ExpressionParser {
// steal the decorators if there are any
if (decorators.length) {
member.decorators = decorators;
if (this.hasPlugin("decorators2")) {
this.resetStartLocationFromNode(member, decorators[0]);
}
decorators = [];
}
this.parseClassMember(classBody, member, state);
if (this.hasPlugin("decorators2") && 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) {
@ -750,6 +790,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)) {

View File

@ -0,0 +1,2 @@
@foo('bar')
class Foo {}

View File

@ -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": 0,
"end": 24,
"loc": {
"start": {
"line": 1,
"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": []
}
}

View File

@ -0,0 +1,4 @@
@abc
class Foo {
}

View File

@ -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": 0,
"end": 19,
"loc": {
"start": {
"line": 1,
"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": []
}
}

View File

@ -0,0 +1,6 @@
var foo = @dec class Bar {
@baz
bam() {
f();
}
}

View File

@ -0,0 +1,308 @@
{
"type": "File",
"start": 0,
"end": 58,
"loc": {
"start": {
"line": 1,
"column": 0
},
"end": {
"line": 6,
"column": 1
}
},
"program": {
"type": "Program",
"start": 0,
"end": 58,
"loc": {
"start": {
"line": 1,
"column": 0
},
"end": {
"line": 6,
"column": 1
}
},
"sourceType": "script",
"body": [
{
"type": "VariableDeclaration",
"start": 0,
"end": 58,
"loc": {
"start": {
"line": 1,
"column": 0
},
"end": {
"line": 6,
"column": 1
}
},
"declarations": [
{
"type": "VariableDeclarator",
"start": 4,
"end": 58,
"loc": {
"start": {
"line": 1,
"column": 4
},
"end": {
"line": 6,
"column": 1
}
},
"id": {
"type": "Identifier",
"start": 4,
"end": 7,
"loc": {
"start": {
"line": 1,
"column": 4
},
"end": {
"line": 1,
"column": 7
},
"identifierName": "foo"
},
"name": "foo"
},
"init": {
"type": "ClassExpression",
"start": 10,
"end": 58,
"loc": {
"start": {
"line": 1,
"column": 10
},
"end": {
"line": 6,
"column": 1
}
},
"decorators": [
{
"type": "Decorator",
"start": 10,
"end": 14,
"loc": {
"start": {
"line": 1,
"column": 10
},
"end": {
"line": 1,
"column": 14
}
},
"expression": {
"type": "Identifier",
"start": 11,
"end": 14,
"loc": {
"start": {
"line": 1,
"column": 11
},
"end": {
"line": 1,
"column": 14
},
"identifierName": "dec"
},
"name": "dec"
}
}
],
"id": {
"type": "Identifier",
"start": 21,
"end": 24,
"loc": {
"start": {
"line": 1,
"column": 21
},
"end": {
"line": 1,
"column": 24
},
"identifierName": "Bar"
},
"name": "Bar"
},
"superClass": null,
"body": {
"type": "ClassBody",
"start": 25,
"end": 58,
"loc": {
"start": {
"line": 1,
"column": 25
},
"end": {
"line": 6,
"column": 1
}
},
"body": [
{
"type": "ClassMethod",
"start": 29,
"end": 56,
"loc": {
"start": {
"line": 2,
"column": 2
},
"end": {
"line": 5,
"column": 3
}
},
"decorators": [
{
"type": "Decorator",
"start": 29,
"end": 33,
"loc": {
"start": {
"line": 2,
"column": 2
},
"end": {
"line": 2,
"column": 6
}
},
"expression": {
"type": "Identifier",
"start": 30,
"end": 33,
"loc": {
"start": {
"line": 2,
"column": 3
},
"end": {
"line": 2,
"column": 6
},
"identifierName": "baz"
},
"name": "baz"
}
}
],
"static": false,
"computed": false,
"key": {
"type": "Identifier",
"start": 36,
"end": 39,
"loc": {
"start": {
"line": 3,
"column": 2
},
"end": {
"line": 3,
"column": 5
},
"identifierName": "bam"
},
"name": "bam"
},
"kind": "method",
"id": null,
"generator": false,
"expression": false,
"async": false,
"params": [],
"body": {
"type": "BlockStatement",
"start": 42,
"end": 56,
"loc": {
"start": {
"line": 3,
"column": 8
},
"end": {
"line": 5,
"column": 3
}
},
"body": [
{
"type": "ExpressionStatement",
"start": 48,
"end": 52,
"loc": {
"start": {
"line": 4,
"column": 4
},
"end": {
"line": 4,
"column": 8
}
},
"expression": {
"type": "CallExpression",
"start": 48,
"end": 51,
"loc": {
"start": {
"line": 4,
"column": 4
},
"end": {
"line": 4,
"column": 7
}
},
"callee": {
"type": "Identifier",
"start": 48,
"end": 49,
"loc": {
"start": {
"line": 4,
"column": 4
},
"end": {
"line": 4,
"column": 5
},
"identifierName": "f"
},
"name": "f"
},
"arguments": []
}
}
],
"directives": []
}
}
]
}
}
}
],
"kind": "var"
}
],
"directives": []
}
}

View File

@ -0,0 +1,3 @@
class A {
@dec *m(){}
}

View File

@ -0,0 +1,175 @@
{
"type": "File",
"start": 0,
"end": 25,
"loc": {
"start": {
"line": 1,
"column": 0
},
"end": {
"line": 3,
"column": 1
}
},
"program": {
"type": "Program",
"start": 0,
"end": 25,
"loc": {
"start": {
"line": 1,
"column": 0
},
"end": {
"line": 3,
"column": 1
}
},
"sourceType": "script",
"body": [
{
"type": "ClassDeclaration",
"start": 0,
"end": 25,
"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": 25,
"loc": {
"start": {
"line": 1,
"column": 8
},
"end": {
"line": 3,
"column": 1
}
},
"body": [
{
"type": "ClassMethod",
"start": 12,
"end": 23,
"loc": {
"start": {
"line": 2,
"column": 2
},
"end": {
"line": 2,
"column": 13
}
},
"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,
"kind": "method",
"computed": false,
"key": {
"type": "Identifier",
"start": 18,
"end": 19,
"loc": {
"start": {
"line": 2,
"column": 8
},
"end": {
"line": 2,
"column": 9
},
"identifierName": "m"
},
"name": "m"
},
"id": null,
"generator": true,
"expression": false,
"async": false,
"params": [],
"body": {
"type": "BlockStatement",
"start": 21,
"end": 23,
"loc": {
"start": {
"line": 2,
"column": 11
},
"end": {
"line": 2,
"column": 13
}
},
"body": [],
"directives": []
}
}
]
}
}
],
"directives": []
}
}

View File

@ -0,0 +1,4 @@
class A {
@a.b.c.d(e, f)
m(){}
}

View File

@ -0,0 +1,325 @@
{
"type": "File",
"start": 0,
"end": 36,
"loc": {
"start": {
"line": 1,
"column": 0
},
"end": {
"line": 4,
"column": 1
}
},
"program": {
"type": "Program",
"start": 0,
"end": 36,
"loc": {
"start": {
"line": 1,
"column": 0
},
"end": {
"line": 4,
"column": 1
}
},
"sourceType": "script",
"body": [
{
"type": "ClassDeclaration",
"start": 0,
"end": 36,
"loc": {
"start": {
"line": 1,
"column": 0
},
"end": {
"line": 4,
"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": 36,
"loc": {
"start": {
"line": 1,
"column": 8
},
"end": {
"line": 4,
"column": 1
}
},
"body": [
{
"type": "ClassMethod",
"start": 12,
"end": 34,
"loc": {
"start": {
"line": 2,
"column": 2
},
"end": {
"line": 3,
"column": 7
}
},
"decorators": [
{
"type": "Decorator",
"start": 12,
"end": 26,
"loc": {
"start": {
"line": 2,
"column": 2
},
"end": {
"line": 2,
"column": 16
}
},
"expression": {
"type": "CallExpression",
"start": 13,
"end": 26,
"loc": {
"start": {
"line": 2,
"column": 3
},
"end": {
"line": 2,
"column": 16
}
},
"callee": {
"type": "MemberExpression",
"start": 13,
"end": 20,
"loc": {
"start": {
"line": 2,
"column": 3
},
"end": {
"line": 2,
"column": 10
}
},
"object": {
"type": "MemberExpression",
"start": 13,
"end": 18,
"loc": {
"start": {
"line": 2,
"column": 3
},
"end": {
"line": 2,
"column": 8
}
},
"object": {
"type": "MemberExpression",
"start": 13,
"end": 16,
"loc": {
"start": {
"line": 2,
"column": 3
},
"end": {
"line": 2,
"column": 6
}
},
"object": {
"type": "Identifier",
"start": 13,
"end": 14,
"loc": {
"start": {
"line": 2,
"column": 3
},
"end": {
"line": 2,
"column": 4
},
"identifierName": "a"
},
"name": "a"
},
"property": {
"type": "Identifier",
"start": 15,
"end": 16,
"loc": {
"start": {
"line": 2,
"column": 5
},
"end": {
"line": 2,
"column": 6
},
"identifierName": "b"
},
"name": "b"
},
"computed": false
},
"property": {
"type": "Identifier",
"start": 17,
"end": 18,
"loc": {
"start": {
"line": 2,
"column": 7
},
"end": {
"line": 2,
"column": 8
},
"identifierName": "c"
},
"name": "c"
},
"computed": false
},
"property": {
"type": "Identifier",
"start": 19,
"end": 20,
"loc": {
"start": {
"line": 2,
"column": 9
},
"end": {
"line": 2,
"column": 10
},
"identifierName": "d"
},
"name": "d"
},
"computed": false
},
"arguments": [
{
"type": "Identifier",
"start": 21,
"end": 22,
"loc": {
"start": {
"line": 2,
"column": 11
},
"end": {
"line": 2,
"column": 12
},
"identifierName": "e"
},
"name": "e"
},
{
"type": "Identifier",
"start": 24,
"end": 25,
"loc": {
"start": {
"line": 2,
"column": 14
},
"end": {
"line": 2,
"column": 15
},
"identifierName": "f"
},
"name": "f"
}
]
}
}
],
"static": false,
"computed": false,
"key": {
"type": "Identifier",
"start": 29,
"end": 30,
"loc": {
"start": {
"line": 3,
"column": 2
},
"end": {
"line": 3,
"column": 3
},
"identifierName": "m"
},
"name": "m"
},
"kind": "method",
"id": null,
"generator": false,
"expression": false,
"async": false,
"params": [],
"body": {
"type": "BlockStatement",
"start": 32,
"end": 34,
"loc": {
"start": {
"line": 3,
"column": 5
},
"end": {
"line": 3,
"column": 7
}
},
"body": [],
"directives": []
}
}
]
}
}
],
"directives": []
}
}

View File

@ -0,0 +1,2 @@
export default
@bar class Foo { }

View File

@ -0,0 +1,132 @@
{
"type": "File",
"start": 0,
"end": 34,
"loc": {
"start": {
"line": 1,
"column": 0
},
"end": {
"line": 2,
"column": 18
}
},
"program": {
"type": "Program",
"start": 0,
"end": 34,
"loc": {
"start": {
"line": 1,
"column": 0
},
"end": {
"line": 2,
"column": 18
}
},
"sourceType": "module",
"body": [
{
"type": "ExportDefaultDeclaration",
"start": 0,
"end": 34,
"loc": {
"start": {
"line": 1,
"column": 0
},
"end": {
"line": 2,
"column": 18
}
},
"declaration": {
"type": "ClassExpression",
"start": 16,
"end": 34,
"loc": {
"start": {
"line": 2,
"column": 0
},
"end": {
"line": 2,
"column": 18
}
},
"decorators": [
{
"type": "Decorator",
"start": 16,
"end": 20,
"loc": {
"start": {
"line": 2,
"column": 0
},
"end": {
"line": 2,
"column": 4
}
},
"expression": {
"type": "Identifier",
"start": 17,
"end": 20,
"loc": {
"start": {
"line": 2,
"column": 1
},
"end": {
"line": 2,
"column": 4
},
"identifierName": "bar"
},
"name": "bar"
}
}
],
"id": {
"type": "Identifier",
"start": 27,
"end": 30,
"loc": {
"start": {
"line": 2,
"column": 11
},
"end": {
"line": 2,
"column": 14
},
"identifierName": "Foo"
},
"name": "Foo"
},
"superClass": null,
"body": {
"type": "ClassBody",
"start": 31,
"end": 34,
"loc": {
"start": {
"line": 2,
"column": 15
},
"end": {
"line": 2,
"column": 18
}
},
"body": []
}
}
}
],
"directives": []
}
}

View File

@ -0,0 +1,3 @@
{
"sourceType": "module"
}

View File

@ -0,0 +1,3 @@
class Foo {
constructor(@foo x) {}
}

View File

@ -0,0 +1,3 @@
{
"throws": "Stage 2 decorators cannot be used to decorate parameters (2:14)"
}

View File

@ -0,0 +1,3 @@
class A {
@dec name = 0
}

View File

@ -0,0 +1,4 @@
{
"plugins": ["classProperties", "decorators2"],
"throws": "Stage 2 decorators may only be used with a class or a class method (2:2)"
}

View File

@ -0,0 +1,6 @@
class Foo {
@bar[bizz]
abc() {
}
}

View File

@ -0,0 +1,4 @@
{
"plugins": ["decorators2", "classProperties"],
"throws": "Stage 2 decorators may only be used with a class or a class method (2:2)"
}

View File

@ -0,0 +1,4 @@
class Foo {
@abc
constructor(){}
}

View File

@ -0,0 +1,3 @@
{
"throws": "You can't attach decorators to a class constructor (2:2)"
}

View File

@ -0,0 +1,2 @@
@foo
export default class {}

View File

@ -0,0 +1,4 @@
{
"sourceType": "module",
"throws": "Leading decorators must be attached to a class declaration (2:0)"
}

View File

@ -0,0 +1 @@
function func(@foo x) {}

View File

@ -0,0 +1,3 @@
{
"throws": "Stage 2 decorators cannot be used to decorate parameters (1:14)"
}

View File

@ -0,0 +1,3 @@
var obj = {
method(@foo x) {}
};

View File

@ -0,0 +1,3 @@
{
"throws": "Stage 2 decorators cannot be used to decorate parameters (2:9)"
}

View File

@ -0,0 +1,5 @@
var o = {
@baz
foo() {
}
}

View File

@ -0,0 +1,3 @@
{
"throws": "Stage 2 decorators disallow object literal property decorators (2:2)"
}

View File

@ -0,0 +1,3 @@
class A {
@dec #name = 0
}

View File

@ -0,0 +1,4 @@
{
"plugins": ["classProperties", "classPrivateProperties", "decorators2"],
"throws": "Stage 2 decorators may only be used with a class or a class method (2:2)"
}

View File

@ -0,0 +1,4 @@
class A {
@a;
m(){}
}

View File

@ -0,0 +1,3 @@
{
"throws": "Decorators must not be followed by a semicolon (2:5)"
}

View File

@ -0,0 +1,3 @@
class A {
@dec static name = 0
}

View File

@ -0,0 +1,4 @@
{
"plugins": ["classProperties", "decorators2"],
"throws": "Stage 2 decorators may only be used with a class or a class method (2:2)"
}

View File

@ -0,0 +1,4 @@
class A {
@dec
['name'](){}
}

View File

@ -0,0 +1,178 @@
{
"type": "File",
"start": 0,
"end": 33,
"loc": {
"start": {
"line": 1,
"column": 0
},
"end": {
"line": 4,
"column": 1
}
},
"program": {
"type": "Program",
"start": 0,
"end": 33,
"loc": {
"start": {
"line": 1,
"column": 0
},
"end": {
"line": 4,
"column": 1
}
},
"sourceType": "script",
"body": [
{
"type": "ClassDeclaration",
"start": 0,
"end": 33,
"loc": {
"start": {
"line": 1,
"column": 0
},
"end": {
"line": 4,
"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": 33,
"loc": {
"start": {
"line": 1,
"column": 8
},
"end": {
"line": 4,
"column": 1
}
},
"body": [
{
"type": "ClassMethod",
"start": 12,
"end": 31,
"loc": {
"start": {
"line": 2,
"column": 2
},
"end": {
"line": 3,
"column": 14
}
},
"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": 20,
"end": 26,
"loc": {
"start": {
"line": 3,
"column": 3
},
"end": {
"line": 3,
"column": 9
}
},
"extra": {
"rawValue": "name",
"raw": "'name'"
},
"value": "name"
},
"kind": "method",
"id": null,
"generator": false,
"expression": false,
"async": false,
"params": [],
"body": {
"type": "BlockStatement",
"start": 29,
"end": 31,
"loc": {
"start": {
"line": 3,
"column": 12
},
"end": {
"line": 3,
"column": 14
}
},
"body": [],
"directives": []
}
}
]
}
}
],
"directives": []
}
}

View File

@ -0,0 +1,3 @@
{
"plugins": ["decorators2"]
}

View File

@ -0,0 +1,2 @@
// we don't need any source code for this error to trigger,
// it should trigger just because both old and new decorator plugins exist together

View File

@ -0,0 +1,4 @@
{
"plugins": ["decorators", "decorators2"],
"throws": "Cannot use decorators and decorators2 plugin together"
}

View File

@ -0,0 +1,2 @@
@(bar.baz)
class Foo {}

View File

@ -0,0 +1,3 @@
{
"throws": "Unexpected token (1:1)"
}

View File

@ -0,0 +1,2 @@
@foo().bar
class Baz {}

View File

@ -0,0 +1,3 @@
{
"throws": "Leading decorators must be attached to a class declaration (1:6)"
}