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
}
},
"callee": {
"expression": {
"type": "Identifier",
"start": 1,
"end": 11,

View File

@ -92,7 +92,7 @@ export function Super() {
export function Decorator(node: Object) {
this.token("@");
this.print(node.callee, node);
this.print(node.expression, node);
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
this.state.decoratorStack.push([]);
if (this.eat(tt.parenL)) {
node.callee = this.parseExpression();
this.expect(tt.parenR);
} else {
const startPos = this.state.start;
const startLoc = this.state.startLoc;
let expr = this.parseIdentifier(false);
let expr: N.Expression;
if (this.eat(tt.parenL)) {
expr = this.parseExpression();
this.expect(tt.parenR);
} else {
expr = this.parseIdentifier(false);
while (this.eat(tt.dot)) {
const node = this.startNodeAt(startPos, startLoc);
@ -301,18 +303,20 @@ export default class StatementParser extends ExpressionParser {
node.computed = false;
expr = this.finishNode(node, "MemberExpression");
}
node.callee = expr;
}
if (this.eat(tt.parenL)) {
const node = this.startNodeAt(startPos, startLoc);
node.callee = expr;
node.arguments = this.parseCallExpressionArguments(tt.parenR, false);
this.toReferencedList(node.arguments);
expr = this.finishNode(node, "CallExpression");
}
node.expression = expr;
this.state.decoratorStack.pop();
} else {
node.callee = this.parseMaybeAssign();
node.expression = this.parseMaybeAssign();
}
return this.finishNode(node, "Decorator");
}

View File

@ -58,6 +58,20 @@
"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,
@ -98,6 +112,7 @@
}
]
}
}
],
"id": {
"type": "Identifier",

View File

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

View File

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

View File

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

View File

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

View File

@ -105,6 +105,20 @@
"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,
@ -258,6 +272,7 @@
}
]
}
}
],
"static": false,
"key": {

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -58,6 +58,20 @@
"column": 2
}
},
"expression": {
"type": "CallExpression",
"start": 1,
"end": 40,
"loc": {
"start": {
"line": 1,
"column": 1
},
"end": {
"line": 3,
"column": 2
}
},
"callee": {
"type": "Identifier",
"start": 1,
@ -154,7 +168,7 @@
"column": 15
}
},
"callee": {
"expression": {
"type": "Identifier",
"start": 19,
"end": 24,
@ -213,6 +227,7 @@
}
]
}
}
],
"id": {
"type": "Identifier",

View File

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

View File

@ -105,6 +105,20 @@
"column": 3
}
},
"expression": {
"type": "CallExpression",
"start": 14,
"end": 91,
"loc": {
"start": {
"line": 2,
"column": 3
},
"end": {
"line": 7,
"column": 3
}
},
"callee": {
"type": "Identifier",
"start": 14,
@ -152,7 +166,7 @@
"column": 13
}
},
"callee": {
"expression": {
"type": "Identifier",
"start": 26,
"end": 34,
@ -217,7 +231,7 @@
"column": 12
}
},
"callee": {
"expression": {
"type": "Identifier",
"start": 51,
"end": 56,
@ -283,6 +297,7 @@
}
]
}
}
],
"static": false,
"key": {

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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