Remove parser support for decorators optional parentheses (#8037)

* Remove parser support for decorators optional parentheses

* Update fixtures
This commit is contained in:
Nicolò Ribaudo 2018-06-02 13:07:15 +02:00 committed by GitHub
parent fe556c502d
commit b8dcd6f593
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
55 changed files with 487 additions and 429 deletions

View File

@ -58,7 +58,7 @@
"column": 11 "column": 11
} }
}, },
"callee": { "expression": {
"type": "Identifier", "type": "Identifier",
"start": 1, "start": 1,
"end": 11, "end": 11,

View File

@ -92,7 +92,7 @@ export function Super() {
export function Decorator(node: Object) { export function Decorator(node: Object) {
this.token("@"); this.token("@");
this.print(node.callee, node); this.print(node.expression, node);
this.newline(); this.newline();
} }

View File

@ -286,13 +286,15 @@ export default class StatementParser extends ExpressionParser {
// So that the decorators of any nested class expressions will be dealt with separately // So that the decorators of any nested class expressions will be dealt with separately
this.state.decoratorStack.push([]); this.state.decoratorStack.push([]);
const startPos = this.state.start;
const startLoc = this.state.startLoc;
let expr: N.Expression;
if (this.eat(tt.parenL)) { if (this.eat(tt.parenL)) {
node.callee = this.parseExpression(); expr = this.parseExpression();
this.expect(tt.parenR); this.expect(tt.parenR);
} else { } else {
const startPos = this.state.start; expr = this.parseIdentifier(false);
const startLoc = this.state.startLoc;
let expr = this.parseIdentifier(false);
while (this.eat(tt.dot)) { while (this.eat(tt.dot)) {
const node = this.startNodeAt(startPos, startLoc); const node = this.startNodeAt(startPos, startLoc);
@ -301,18 +303,20 @@ export default class StatementParser extends ExpressionParser {
node.computed = false; node.computed = false;
expr = this.finishNode(node, "MemberExpression"); expr = this.finishNode(node, "MemberExpression");
} }
node.callee = expr;
} }
if (this.eat(tt.parenL)) { if (this.eat(tt.parenL)) {
const node = this.startNodeAt(startPos, startLoc);
node.callee = expr;
node.arguments = this.parseCallExpressionArguments(tt.parenR, false); node.arguments = this.parseCallExpressionArguments(tt.parenR, false);
this.toReferencedList(node.arguments); this.toReferencedList(node.arguments);
expr = this.finishNode(node, "CallExpression");
} }
node.expression = expr;
this.state.decoratorStack.pop(); this.state.decoratorStack.pop();
} else { } else {
node.callee = this.parseMaybeAssign(); node.expression = this.parseMaybeAssign();
} }
return this.finishNode(node, "Decorator"); return this.finishNode(node, "Decorator");
} }

View File

@ -58,10 +58,10 @@
"column": 11 "column": 11
} }
}, },
"callee": { "expression": {
"type": "Identifier", "type": "CallExpression",
"start": 1, "start": 1,
"end": 4, "end": 11,
"loc": { "loc": {
"start": { "start": {
"line": 1, "line": 1,
@ -69,34 +69,49 @@
}, },
"end": { "end": {
"line": 1, "line": 1,
"column": 4 "column": 11
}, }
"identifierName": "foo"
}, },
"name": "foo" "callee": {
}, "type": "Identifier",
"arguments": [ "start": 1,
{ "end": 4,
"type": "StringLiteral",
"start": 5,
"end": 10,
"loc": { "loc": {
"start": { "start": {
"line": 1, "line": 1,
"column": 5 "column": 1
}, },
"end": { "end": {
"line": 1, "line": 1,
"column": 10 "column": 4
} },
"identifierName": "foo"
}, },
"extra": { "name": "foo"
"rawValue": "bar", },
"raw": "'bar'" "arguments": [
}, {
"value": "bar" "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": { "id": {

View File

@ -58,7 +58,7 @@
"column": 4 "column": 4
} }
}, },
"callee": { "expression": {
"type": "Identifier", "type": "Identifier",
"start": 1, "start": 1,
"end": 4, "end": 4,

View File

@ -104,7 +104,7 @@
"column": 14 "column": 14
} }
}, },
"callee": { "expression": {
"type": "Identifier", "type": "Identifier",
"start": 11, "start": 11,
"end": 14, "end": 14,
@ -185,7 +185,7 @@
"column": 6 "column": 6
} }
}, },
"callee": { "expression": {
"type": "Identifier", "type": "Identifier",
"start": 30, "start": 30,
"end": 33, "end": 33,

View File

@ -105,7 +105,7 @@
"column": 6 "column": 6
} }
}, },
"callee": { "expression": {
"type": "Identifier", "type": "Identifier",
"start": 13, "start": 13,
"end": 16, "end": 16,

View File

@ -105,7 +105,7 @@
"column": 6 "column": 6
} }
}, },
"callee": { "expression": {
"type": "Identifier", "type": "Identifier",
"start": 13, "start": 13,
"end": 16, "end": 16,

View File

@ -105,10 +105,10 @@
"column": 16 "column": 16
} }
}, },
"callee": { "expression": {
"type": "MemberExpression", "type": "CallExpression",
"start": 13, "start": 13,
"end": 20, "end": 26,
"loc": { "loc": {
"start": { "start": {
"line": 2, "line": 2,
@ -116,13 +116,13 @@
}, },
"end": { "end": {
"line": 2, "line": 2,
"column": 10 "column": 16
} }
}, },
"object": { "callee": {
"type": "MemberExpression", "type": "MemberExpression",
"start": 13, "start": 13,
"end": 18, "end": 20,
"loc": { "loc": {
"start": { "start": {
"line": 2, "line": 2,
@ -130,13 +130,13 @@
}, },
"end": { "end": {
"line": 2, "line": 2,
"column": 8 "column": 10
} }
}, },
"object": { "object": {
"type": "MemberExpression", "type": "MemberExpression",
"start": 13, "start": 13,
"end": 16, "end": 18,
"loc": { "loc": {
"start": { "start": {
"line": 2, "line": 2,
@ -144,13 +144,13 @@
}, },
"end": { "end": {
"line": 2, "line": 2,
"column": 6 "column": 8
} }
}, },
"object": { "object": {
"type": "Identifier", "type": "MemberExpression",
"start": 13, "start": 13,
"end": 14, "end": 16,
"loc": { "loc": {
"start": { "start": {
"line": 2, "line": 2,
@ -158,105 +158,120 @@
}, },
"end": { "end": {
"line": 2, "line": 2,
"column": 4 "column": 6
}, }
"identifierName": "a"
}, },
"name": "a" "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": { "property": {
"type": "Identifier", "type": "Identifier",
"start": 15, "start": 17,
"end": 16, "end": 18,
"loc": { "loc": {
"start": { "start": {
"line": 2, "line": 2,
"column": 5 "column": 7
}, },
"end": { "end": {
"line": 2, "line": 2,
"column": 6 "column": 8
}, },
"identifierName": "b" "identifierName": "c"
}, },
"name": "b" "name": "c"
}, },
"computed": false "computed": false
}, },
"property": { "property": {
"type": "Identifier", "type": "Identifier",
"start": 17, "start": 19,
"end": 18, "end": 20,
"loc": { "loc": {
"start": { "start": {
"line": 2, "line": 2,
"column": 7 "column": 9
}, },
"end": { "end": {
"line": 2, "line": 2,
"column": 8 "column": 10
}, },
"identifierName": "c" "identifierName": "d"
}, },
"name": "c" "name": "d"
}, },
"computed": false "computed": false
}, },
"property": { "arguments": [
"type": "Identifier", {
"start": 19, "type": "Identifier",
"end": 20, "start": 21,
"loc": { "end": 22,
"start": { "loc": {
"line": 2, "start": {
"column": 9 "line": 2,
"column": 11
},
"end": {
"line": 2,
"column": 12
},
"identifierName": "e"
}, },
"end": { "name": "e"
"line": 2,
"column": 10
},
"identifierName": "d"
}, },
"name": "d" {
}, "type": "Identifier",
"computed": false "start": 24,
}, "end": 25,
"arguments": [ "loc": {
{ "start": {
"type": "Identifier", "line": 2,
"start": 21, "column": 14
"end": 22, },
"loc": { "end": {
"start": { "line": 2,
"line": 2, "column": 15
"column": 11 },
"identifierName": "f"
}, },
"end": { "name": "f"
"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, "static": false,

View File

@ -105,7 +105,7 @@
"column": 6 "column": 6
} }
}, },
"callee": { "expression": {
"type": "Identifier", "type": "Identifier",
"start": 15, "start": 15,
"end": 18, "end": 18,

View File

@ -72,7 +72,7 @@
"column": 26 "column": 26
} }
}, },
"callee": { "expression": {
"type": "Identifier", "type": "Identifier",
"start": 17, "start": 17,
"end": 26, "end": 26,

View File

@ -72,7 +72,7 @@
"column": 10 "column": 10
} }
}, },
"callee": { "expression": {
"type": "Identifier", "type": "Identifier",
"start": 1, "start": 1,
"end": 10, "end": 10,

View File

@ -74,7 +74,7 @@
"column": 10 "column": 10
} }
}, },
"callee": { "expression": {
"type": "Identifier", "type": "Identifier",
"start": 1, "start": 1,
"end": 10, "end": 10,

View File

@ -74,7 +74,7 @@
"column": 11 "column": 11
} }
}, },
"callee": { "expression": {
"type": "Identifier", "type": "Identifier",
"start": 8, "start": 8,
"end": 11, "end": 11,

View File

@ -72,7 +72,7 @@
"column": 4 "column": 4
} }
}, },
"callee": { "expression": {
"type": "Identifier", "type": "Identifier",
"start": 17, "start": 17,
"end": 20, "end": 20,

View File

@ -105,7 +105,7 @@
"column": 6 "column": 6
} }
}, },
"callee": { "expression": {
"type": "Identifier", "type": "Identifier",
"start": 13, "start": 13,
"end": 16, "end": 16,

View File

@ -58,160 +58,175 @@
"column": 2 "column": 2
} }
}, },
"callee": { "expression": {
"type": "Identifier", "type": "CallExpression",
"start": 1, "start": 1,
"end": 6, "end": 40,
"loc": { "loc": {
"start": { "start": {
"line": 1, "line": 1,
"column": 1 "column": 1
}, },
"end": { "end": {
"line": 1, "line": 3,
"column": 6 "column": 2
}, }
"identifierName": "outer"
}, },
"name": "outer" "callee": {
}, "type": "Identifier",
"arguments": [ "start": 1,
{ "end": 6,
"type": "ObjectExpression",
"start": 7,
"end": 39,
"loc": { "loc": {
"start": { "start": {
"line": 1, "line": 1,
"column": 7 "column": 1
}, },
"end": { "end": {
"line": 3, "line": 1,
"column": 1 "column": 6
} },
"identifierName": "outer"
}, },
"properties": [ "name": "outer"
{ },
"type": "ObjectProperty", "arguments": [
"start": 11, {
"end": 37, "type": "ObjectExpression",
"loc": { "start": 7,
"start": { "end": 39,
"line": 2, "loc": {
"column": 2 "start": {
}, "line": 1,
"end": { "column": 7
"line": 2,
"column": 28
}
}, },
"method": false, "end": {
"key": { "line": 3,
"type": "Identifier", "column": 1
}
},
"properties": [
{
"type": "ObjectProperty",
"start": 11, "start": 11,
"end": 16, "end": 37,
"loc": { "loc": {
"start": { "start": {
"line": 2, "line": 2,
"column": 2 "column": 2
}, },
"end": {
"line": 2,
"column": 7
},
"identifierName": "store"
},
"name": "store"
},
"computed": false,
"shorthand": false,
"value": {
"type": "ClassExpression",
"start": 18,
"end": 37,
"loc": {
"start": {
"line": 2,
"column": 9
},
"end": { "end": {
"line": 2, "line": 2,
"column": 28 "column": 28
} }
}, },
"decorators": [ "method": false,
{ "key": {
"type": "Decorator",
"start": 18,
"end": 24,
"loc": {
"start": {
"line": 2,
"column": 9
},
"end": {
"line": 2,
"column": 15
}
},
"callee": {
"type": "Identifier",
"start": 19,
"end": 24,
"loc": {
"start": {
"line": 2,
"column": 10
},
"end": {
"line": 2,
"column": 15
},
"identifierName": "inner"
},
"name": "inner"
}
}
],
"id": {
"type": "Identifier", "type": "Identifier",
"start": 31, "start": 11,
"end": 34, "end": 16,
"loc": { "loc": {
"start": { "start": {
"line": 2, "line": 2,
"column": 22 "column": 2
}, },
"end": { "end": {
"line": 2, "line": 2,
"column": 25 "column": 7
}, },
"identifierName": "Foo" "identifierName": "store"
}, },
"name": "Foo" "name": "store"
}, },
"superClass": null, "computed": false,
"body": { "shorthand": false,
"type": "ClassBody", "value": {
"start": 35, "type": "ClassExpression",
"start": 18,
"end": 37, "end": 37,
"loc": { "loc": {
"start": { "start": {
"line": 2, "line": 2,
"column": 26 "column": 9
}, },
"end": { "end": {
"line": 2, "line": 2,
"column": 28 "column": 28
} }
}, },
"body": [] "decorators": [
{
"type": "Decorator",
"start": 18,
"end": 24,
"loc": {
"start": {
"line": 2,
"column": 9
},
"end": {
"line": 2,
"column": 15
}
},
"expression": {
"type": "Identifier",
"start": 19,
"end": 24,
"loc": {
"start": {
"line": 2,
"column": 10
},
"end": {
"line": 2,
"column": 15
},
"identifierName": "inner"
},
"name": "inner"
}
}
],
"id": {
"type": "Identifier",
"start": 31,
"end": 34,
"loc": {
"start": {
"line": 2,
"column": 22
},
"end": {
"line": 2,
"column": 25
},
"identifierName": "Foo"
},
"name": "Foo"
},
"superClass": null,
"body": {
"type": "ClassBody",
"start": 35,
"end": 37,
"loc": {
"start": {
"line": 2,
"column": 26
},
"end": {
"line": 2,
"column": 28
}
},
"body": []
}
} }
} }
} ]
] }
} ]
] }
} }
], ],
"id": { "id": {

View File

@ -58,7 +58,7 @@
"column": 2 "column": 2
} }
}, },
"callee": { "expression": {
"type": "ObjectExpression", "type": "ObjectExpression",
"start": 2, "start": 2,
"end": 34, "end": 34,
@ -136,7 +136,7 @@
"column": 15 "column": 15
} }
}, },
"callee": { "expression": {
"type": "Identifier", "type": "Identifier",
"start": 14, "start": 14,
"end": 19, "end": 19,

View File

@ -105,183 +105,198 @@
"column": 3 "column": 3
} }
}, },
"callee": { "expression": {
"type": "Identifier", "type": "CallExpression",
"start": 14, "start": 14,
"end": 19, "end": 91,
"loc": { "loc": {
"start": { "start": {
"line": 2, "line": 2,
"column": 3 "column": 3
}, },
"end": { "end": {
"line": 2, "line": 7,
"column": 8 "column": 3
}, }
"identifierName": "outer"
}, },
"name": "outer" "callee": {
}, "type": "Identifier",
"arguments": [ "start": 14,
{ "end": 19,
"type": "ClassExpression",
"start": 25,
"end": 87,
"loc": { "loc": {
"start": { "start": {
"line": 3, "line": 2,
"column": 4 "column": 3
}, },
"end": { "end": {
"line": 6, "line": 2,
"column": 5 "column": 8
} },
"identifierName": "outer"
}, },
"decorators": [ "name": "outer"
{ },
"type": "Decorator", "arguments": [
"start": 25, {
"end": 34, "type": "ClassExpression",
"loc": { "start": 25,
"start": {
"line": 3,
"column": 4
},
"end": {
"line": 3,
"column": 13
}
},
"callee": {
"type": "Identifier",
"start": 26,
"end": 34,
"loc": {
"start": {
"line": 3,
"column": 5
},
"end": {
"line": 3,
"column": 13
},
"identifierName": "classDec"
},
"name": "classDec"
}
}
],
"id": null,
"superClass": null,
"body": {
"type": "ClassBody",
"start": 41,
"end": 87, "end": 87,
"loc": { "loc": {
"start": { "start": {
"line": 3, "line": 3,
"column": 20 "column": 4
}, },
"end": { "end": {
"line": 6, "line": 6,
"column": 5 "column": 5
} }
}, },
"body": [ "decorators": [
{ {
"type": "ClassMethod", "type": "Decorator",
"start": 50, "start": 25,
"end": 80, "end": 34,
"loc": { "loc": {
"start": { "start": {
"line": 4, "line": 3,
"column": 6 "column": 4
}, },
"end": { "end": {
"line": 5, "line": 3,
"column": 22 "column": 13
} }
}, },
"decorators": [ "expression": {
{
"type": "Decorator",
"start": 50,
"end": 56,
"loc": {
"start": {
"line": 4,
"column": 6
},
"end": {
"line": 4,
"column": 12
}
},
"callee": {
"type": "Identifier",
"start": 51,
"end": 56,
"loc": {
"start": {
"line": 4,
"column": 7
},
"end": {
"line": 4,
"column": 12
},
"identifierName": "inner"
},
"name": "inner"
}
}
],
"static": false,
"key": {
"type": "Identifier", "type": "Identifier",
"start": 64, "start": 26,
"end": 75, "end": 34,
"loc": { "loc": {
"start": { "start": {
"line": 5, "line": 3,
"column": 6 "column": 5
}, },
"end": { "end": {
"line": 5, "line": 3,
"column": 17 "column": 13
}, },
"identifierName": "innerMethod" "identifierName": "classDec"
}, },
"name": "innerMethod" "name": "classDec"
}
}
],
"id": null,
"superClass": null,
"body": {
"type": "ClassBody",
"start": 41,
"end": 87,
"loc": {
"start": {
"line": 3,
"column": 20
}, },
"computed": false, "end": {
"kind": "method", "line": 6,
"id": null, "column": 5
"generator": false, }
"async": false, },
"params": [], "body": [
"body": { {
"type": "BlockStatement", "type": "ClassMethod",
"start": 78, "start": 50,
"end": 80, "end": 80,
"loc": { "loc": {
"start": { "start": {
"line": 5, "line": 4,
"column": 20 "column": 6
}, },
"end": { "end": {
"line": 5, "line": 5,
"column": 22 "column": 22
} }
}, },
"body": [], "decorators": [
"directives": [] {
"type": "Decorator",
"start": 50,
"end": 56,
"loc": {
"start": {
"line": 4,
"column": 6
},
"end": {
"line": 4,
"column": 12
}
},
"expression": {
"type": "Identifier",
"start": 51,
"end": 56,
"loc": {
"start": {
"line": 4,
"column": 7
},
"end": {
"line": 4,
"column": 12
},
"identifierName": "inner"
},
"name": "inner"
}
}
],
"static": false,
"key": {
"type": "Identifier",
"start": 64,
"end": 75,
"loc": {
"start": {
"line": 5,
"column": 6
},
"end": {
"line": 5,
"column": 17
},
"identifierName": "innerMethod"
},
"name": "innerMethod"
},
"computed": false,
"kind": "method",
"id": null,
"generator": false,
"async": false,
"params": [],
"body": {
"type": "BlockStatement",
"start": 78,
"end": 80,
"loc": {
"start": {
"line": 5,
"column": 20
},
"end": {
"line": 5,
"column": 22
}
},
"body": [],
"directives": []
}
} }
} ]
] }
} }
} ]
] }
} }
], ],
"static": false, "static": false,

View File

@ -105,7 +105,7 @@
"column": 3 "column": 3
} }
}, },
"callee": { "expression": {
"type": "ClassExpression", "type": "ClassExpression",
"start": 20, "start": 20,
"end": 82, "end": 82,
@ -134,7 +134,7 @@
"column": 13 "column": 13
} }
}, },
"callee": { "expression": {
"type": "Identifier", "type": "Identifier",
"start": 21, "start": 21,
"end": 29, "end": 29,
@ -199,7 +199,7 @@
"column": 12 "column": 12
} }
}, },
"callee": { "expression": {
"type": "Identifier", "type": "Identifier",
"start": 46, "start": 46,
"end": 51, "end": 51,

View File

@ -105,7 +105,7 @@
"column": 6 "column": 6
} }
}, },
"callee": { "expression": {
"type": "Identifier", "type": "Identifier",
"start": 13, "start": 13,
"end": 16, "end": 16,

View File

@ -58,7 +58,7 @@
"column": 12 "column": 12
} }
}, },
"callee": { "expression": {
"type": "MemberExpression", "type": "MemberExpression",
"start": 2, "start": 2,
"end": 11, "end": 11,
@ -188,7 +188,7 @@
"column": 23 "column": 23
} }
}, },
"callee": { "expression": {
"type": "MemberExpression", "type": "MemberExpression",
"start": 29, "start": 29,
"end": 47, "end": 47,
@ -311,7 +311,7 @@
"column": 14 "column": 14
} }
}, },
"callee": { "expression": {
"type": "BinaryExpression", "type": "BinaryExpression",
"start": 66, "start": 66,
"end": 75, "end": 75,

View File

@ -105,7 +105,7 @@
"column": 6 "column": 6
} }
}, },
"callee": { "expression": {
"type": "Identifier", "type": "Identifier",
"start": 13, "start": 13,
"end": 16, "end": 16,

View File

@ -105,7 +105,7 @@
"column": 6 "column": 6
} }
}, },
"callee": { "expression": {
"type": "Identifier", "type": "Identifier",
"start": 13, "start": 13,
"end": 16, "end": 16,

View File

@ -105,7 +105,7 @@
"column": 6 "column": 6
} }
}, },
"callee": { "expression": {
"type": "Identifier", "type": "Identifier",
"start": 15, "start": 15,
"end": 18, "end": 18,

View File

@ -105,7 +105,7 @@
"column": 6 "column": 6
} }
}, },
"callee": { "expression": {
"type": "Identifier", "type": "Identifier",
"start": 13, "start": 13,
"end": 16, "end": 16,

View File

@ -104,7 +104,7 @@
"column": 14 "column": 14
} }
}, },
"callee": { "expression": {
"type": "Identifier", "type": "Identifier",
"start": 11, "start": 11,
"end": 14, "end": 14,

View File

@ -58,7 +58,7 @@
"column": 11 "column": 11
} }
}, },
"callee": { "expression": {
"type": "CallExpression", "type": "CallExpression",
"start": 1, "start": 1,
"end": 11, "end": 11,

View File

@ -105,7 +105,7 @@
"column": 16 "column": 16
} }
}, },
"callee": { "expression": {
"type": "Identifier", "type": "Identifier",
"start": 13, "start": 13,
"end": 16, "end": 16,

View File

@ -58,7 +58,7 @@
"column": 4 "column": 4
} }
}, },
"callee": { "expression": {
"type": "Identifier", "type": "Identifier",
"start": 1, "start": 1,
"end": 4, "end": 4,

View File

@ -105,7 +105,7 @@
"column": 16 "column": 16
} }
}, },
"callee": { "expression": {
"type": "Identifier", "type": "Identifier",
"start": 13, "start": 13,
"end": 16, "end": 16,

View File

@ -58,7 +58,7 @@
"column": 4 "column": 4
} }
}, },
"callee": { "expression": {
"type": "Identifier", "type": "Identifier",
"start": 1, "start": 1,
"end": 4, "end": 4,

View File

@ -105,7 +105,7 @@
"column": 16 "column": 16
} }
}, },
"callee": { "expression": {
"type": "Identifier", "type": "Identifier",
"start": 13, "start": 13,
"end": 16, "end": 16,
@ -137,7 +137,7 @@
"column": 21 "column": 21
} }
}, },
"callee": { "expression": {
"type": "Identifier", "type": "Identifier",
"start": 18, "start": 18,
"end": 21, "end": 21,

View File

@ -145,7 +145,7 @@
"column": 20 "column": 20
} }
}, },
"callee": { "expression": {
"type": "CallExpression", "type": "CallExpression",
"start": 27, "start": 27,
"end": 32, "end": 32,
@ -212,7 +212,7 @@
"column": 40 "column": 40
} }
}, },
"callee": { "expression": {
"type": "CallExpression", "type": "CallExpression",
"start": 37, "start": 37,
"end": 52, "end": 52,
@ -333,7 +333,7 @@
"column": 47 "column": 47
} }
}, },
"callee": { "expression": {
"type": "CallExpression", "type": "CallExpression",
"start": 54, "start": 54,
"end": 59, "end": 59,

View File

@ -105,7 +105,7 @@
"column": 11 "column": 11
} }
}, },
"callee": { "expression": {
"type": "MemberExpression", "type": "MemberExpression",
"start": 15, "start": 15,
"end": 23, "end": 23,

View File

@ -105,7 +105,7 @@
"column": 12 "column": 12
} }
}, },
"callee": { "expression": {
"type": "MemberExpression", "type": "MemberExpression",
"start": 15, "start": 15,
"end": 24, "end": 24,

View File

@ -74,7 +74,7 @@
"column": 4 "column": 4
} }
}, },
"callee": { "expression": {
"type": "Identifier", "type": "Identifier",
"start": 1, "start": 1,
"end": 4, "end": 4,

View File

@ -108,7 +108,7 @@
"column": 35 "column": 35
} }
}, },
"callee": { "expression": {
"type": "CallExpression", "type": "CallExpression",
"start": 30, "start": 30,
"end": 35, "end": 35,
@ -175,7 +175,7 @@
"column": 55 "column": 55
} }
}, },
"callee": { "expression": {
"type": "CallExpression", "type": "CallExpression",
"start": 40, "start": 40,
"end": 55, "end": 55,
@ -296,7 +296,7 @@
"column": 62 "column": 62
} }
}, },
"callee": { "expression": {
"type": "CallExpression", "type": "CallExpression",
"start": 57, "start": 57,
"end": 62, "end": 62,

View File

@ -72,7 +72,7 @@
"column": 4 "column": 4
} }
}, },
"callee": { "expression": {
"type": "Identifier", "type": "Identifier",
"start": 1, "start": 1,
"end": 4, "end": 4,

View File

@ -72,7 +72,7 @@
"column": 16 "column": 16
} }
}, },
"callee": { "expression": {
"type": "Identifier", "type": "Identifier",
"start": 1, "start": 1,
"end": 16, "end": 16,

View File

@ -94,7 +94,7 @@
"column": 20 "column": 20
} }
}, },
"callee": { "expression": {
"type": "CallExpression", "type": "CallExpression",
"start": 15, "start": 15,
"end": 20, "end": 20,
@ -161,7 +161,7 @@
"column": 40 "column": 40
} }
}, },
"callee": { "expression": {
"type": "CallExpression", "type": "CallExpression",
"start": 25, "start": 25,
"end": 40, "end": 40,
@ -282,7 +282,7 @@
"column": 47 "column": 47
} }
}, },
"callee": { "expression": {
"type": "CallExpression", "type": "CallExpression",
"start": 42, "start": 42,
"end": 47, "end": 47,

View File

@ -124,7 +124,7 @@
"column": 29 "column": 29
} }
}, },
"callee": { "expression": {
"type": "CallExpression", "type": "CallExpression",
"start": 24, "start": 24,
"end": 29, "end": 29,
@ -191,7 +191,7 @@
"column": 49 "column": 49
} }
}, },
"callee": { "expression": {
"type": "CallExpression", "type": "CallExpression",
"start": 34, "start": 34,
"end": 49, "end": 49,
@ -312,7 +312,7 @@
"column": 56 "column": 56
} }
}, },
"callee": { "expression": {
"type": "CallExpression", "type": "CallExpression",
"start": 51, "start": 51,
"end": 56, "end": 56,

View File

@ -105,7 +105,7 @@
"column": 16 "column": 16
} }
}, },
"callee": { "expression": {
"type": "Identifier", "type": "Identifier",
"start": 13, "start": 13,
"end": 16, "end": 16,

View File

@ -58,7 +58,7 @@
"column": 25 "column": 25
} }
}, },
"callee": { "expression": {
"type": "CallExpression", "type": "CallExpression",
"start": 1, "start": 1,
"end": 25, "end": 25,
@ -134,7 +134,7 @@
"column": 11 "column": 11
} }
}, },
"callee": { "expression": {
"type": "Identifier", "type": "Identifier",
"start": 8, "start": 8,
"end": 11, "end": 11,
@ -213,7 +213,7 @@
"column": 30 "column": 30
} }
}, },
"callee": { "expression": {
"type": "Identifier", "type": "Identifier",
"start": 27, "start": 27,
"end": 30, "end": 30,

View File

@ -159,7 +159,7 @@
"column": 15 "column": 15
} }
}, },
"callee": { "expression": {
"type": "CallExpression", "type": "CallExpression",
"start": 22, "start": 22,
"end": 27, "end": 27,
@ -226,7 +226,7 @@
"column": 35 "column": 35
} }
}, },
"callee": { "expression": {
"type": "CallExpression", "type": "CallExpression",
"start": 32, "start": 32,
"end": 47, "end": 47,
@ -347,7 +347,7 @@
"column": 42 "column": 42
} }
}, },
"callee": { "expression": {
"type": "CallExpression", "type": "CallExpression",
"start": 49, "start": 49,
"end": 54, "end": 54,

View File

@ -58,7 +58,7 @@
"column": 4 "column": 4
} }
}, },
"callee": { "expression": {
"type": "Identifier", "type": "Identifier",
"start": 1, "start": 1,
"end": 4, "end": 4,
@ -123,7 +123,7 @@
"column": 27 "column": 27
} }
}, },
"callee": { "expression": {
"type": "Identifier", "type": "Identifier",
"start": 24, "start": 24,
"end": 27, "end": 27,

View File

@ -105,7 +105,7 @@
"column": 16 "column": 16
} }
}, },
"callee": { "expression": {
"type": "Identifier", "type": "Identifier",
"start": 13, "start": 13,
"end": 16, "end": 16,

View File

@ -105,7 +105,7 @@
"column": 16 "column": 16
} }
}, },
"callee": { "expression": {
"type": "Identifier", "type": "Identifier",
"start": 13, "start": 13,
"end": 16, "end": 16,

View File

@ -119,7 +119,7 @@
"column": 16 "column": 16
} }
}, },
"callee": { "expression": {
"type": "Identifier", "type": "Identifier",
"start": 13, "start": 13,
"end": 16, "end": 16,

View File

@ -58,7 +58,7 @@
"column": 24 "column": 24
} }
}, },
"callee": { "expression": {
"type": "CallExpression", "type": "CallExpression",
"start": 1, "start": 1,
"end": 24, "end": 24,

View File

@ -143,7 +143,7 @@
"column": 20 "column": 20
} }
}, },
"callee": { "expression": {
"type": "Identifier", "type": "Identifier",
"start": 27, "start": 27,
"end": 30, "end": 30,

View File

@ -59,7 +59,7 @@
"column": 11 "column": 11
} }
}, },
"callee": { "expression": {
"type": "CallExpression", "type": "CallExpression",
"start": 1, "start": 1,
"end": 11, "end": 11,

View File

@ -39,18 +39,18 @@ function applyEnsureOrdering(path) {
).reduce((acc, prop) => acc.concat(prop.node.decorators || []), []); ).reduce((acc, prop) => acc.concat(prop.node.decorators || []), []);
const identDecorators = decorators.filter( const identDecorators = decorators.filter(
decorator => !t.isIdentifier(decorator.callee), decorator => !t.isIdentifier(decorator.expression),
); );
if (identDecorators.length === 0) return; if (identDecorators.length === 0) return;
return t.sequenceExpression( return t.sequenceExpression(
identDecorators identDecorators
.map(decorator => { .map(decorator => {
const callee = decorator.callee; const expression = decorator.expression;
const id = (decorator.callee = path.scope.generateDeclaredUidIdentifier( const id = (decorator.expression = path.scope.generateDeclaredUidIdentifier(
"dec", "dec",
)); ));
return t.assignmentExpression("=", id, callee); return t.assignmentExpression("=", id, expression);
}) })
.concat([path.node]), .concat([path.node]),
); );
@ -69,7 +69,7 @@ function applyClassDecorators(classPath) {
const name = classPath.scope.generateDeclaredUidIdentifier("class"); const name = classPath.scope.generateDeclaredUidIdentifier("class");
return decorators return decorators
.map(dec => dec.callee) .map(dec => dec.expression)
.reverse() .reverse()
.reduce(function(acc, decorator) { .reduce(function(acc, decorator) {
return buildClassDecorator({ return buildClassDecorator({
@ -164,7 +164,9 @@ function applyTargetDecorators(path, state, decoratedProps) {
t.callExpression(state.addHelper("applyDecoratedDescriptor"), [ t.callExpression(state.addHelper("applyDecoratedDescriptor"), [
t.cloneNode(target), t.cloneNode(target),
t.cloneNode(property), t.cloneNode(property),
t.arrayExpression(decorators.map(dec => t.cloneNode(dec.callee))), t.arrayExpression(
decorators.map(dec => t.cloneNode(dec.expression)),
),
t.objectExpression([ t.objectExpression([
t.objectProperty( t.objectProperty(
t.identifier("enumerable"), t.identifier("enumerable"),
@ -180,7 +182,7 @@ function applyTargetDecorators(path, state, decoratedProps) {
t.callExpression(state.addHelper("applyDecoratedDescriptor"), [ t.callExpression(state.addHelper("applyDecoratedDescriptor"), [
t.cloneNode(target), t.cloneNode(target),
t.cloneNode(property), t.cloneNode(property),
t.arrayExpression(decorators.map(dec => t.cloneNode(dec.callee))), t.arrayExpression(decorators.map(dec => t.cloneNode(dec.expression))),
t.isObjectProperty(node) || t.isClassProperty(node, { static: true }) t.isObjectProperty(node) || t.isClassProperty(node, { static: true })
? buildGetObjectInitializer({ ? buildGetObjectInitializer({
TEMP: path.scope.generateDeclaredUidIdentifier("init"), TEMP: path.scope.generateDeclaredUidIdentifier("init"),

View File

@ -600,13 +600,12 @@ Aliases: `Flow`, `FlowPredicate`
### decorator ### decorator
```javascript ```javascript
t.decorator(callee, arguments) t.decorator(expression)
``` ```
See also `t.isDecorator(node, opts)` and `t.assertDecorator(node, opts)`. See also `t.isDecorator(node, opts)` and `t.assertDecorator(node, opts)`.
- `callee`: `Expression` (required) - `expression`: `Expression` (required)
- `arguments`: `Array<Expression | SpreadElement>` (default: `null`)
--- ---

View File

@ -136,18 +136,11 @@ defineType("Import", {
}); });
defineType("Decorator", { defineType("Decorator", {
visitor: ["callee", "arguments"], visitor: ["expression"],
fields: { fields: {
callee: { expression: {
validate: assertNodeType("Expression"), validate: assertNodeType("Expression"),
}, },
arguments: {
optional: true,
validate: chain(
assertValueType("array"),
assertEach(assertNodeType("Expression", "SpreadElement")),
),
},
}, },
}); });