Let decorator stage 2 parsing be under a new plugin name
Parse stage 0 decorators when "decorators" plugin is active and parse stage 2 decorators when "decorators-stage-2" plugin is active
This commit is contained in:
parent
06afa0761b
commit
a24dc6e630
@ -172,34 +172,38 @@ export default class StatementParser extends ExpressionParser {
|
|||||||
}
|
}
|
||||||
|
|
||||||
parseDecorator(): N.Decorator {
|
parseDecorator(): N.Decorator {
|
||||||
if (!this.hasPlugin("decorators")) {
|
if (!(this.hasPlugin("decorators") || this.hasPlugin("decorators-stage-2"))) {
|
||||||
this.unexpected();
|
this.unexpected();
|
||||||
}
|
}
|
||||||
|
|
||||||
const node = this.startNode();
|
const node = this.startNode();
|
||||||
this.next();
|
this.next();
|
||||||
|
|
||||||
const startPos = this.state.start;
|
if (this.hasPlugin("decorators-stage-2")) {
|
||||||
const startLoc = this.state.startLoc;
|
const startPos = this.state.start;
|
||||||
let 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);
|
||||||
node.object = expr;
|
node.object = expr;
|
||||||
node.property = this.parseIdentifier(true);
|
node.property = this.parseIdentifier(true);
|
||||||
node.computed = false;
|
node.computed = false;
|
||||||
expr = this.finishNode(node, "MemberExpression");
|
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();
|
||||||
}
|
}
|
||||||
|
|
||||||
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;
|
|
||||||
return this.finishNode(node, "Decorator");
|
return this.finishNode(node, "Decorator");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user