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:
Peeyush Kushwaha 2017-06-17 13:25:21 +05:30
parent 06afa0761b
commit a24dc6e630

View File

@ -172,34 +172,38 @@ export default class StatementParser extends ExpressionParser {
}
parseDecorator(): N.Decorator {
if (!this.hasPlugin("decorators")) {
if (!(this.hasPlugin("decorators") || this.hasPlugin("decorators-stage-2"))) {
this.unexpected();
}
const node = this.startNode();
this.next();
const startPos = this.state.start;
const startLoc = this.state.startLoc;
let expr = this.parseIdentifier(false);
if (this.hasPlugin("decorators-stage-2")) {
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");
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();
}
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");
}