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,13 +172,14 @@ 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();
if (this.hasPlugin("decorators-stage-2")) {
const startPos = this.state.start; const startPos = this.state.start;
const startLoc = this.state.startLoc; const startLoc = this.state.startLoc;
let expr = this.parseIdentifier(false); let expr = this.parseIdentifier(false);
@ -200,6 +201,9 @@ export default class StatementParser extends ExpressionParser {
} }
node.expression = expr; node.expression = expr;
} else {
node.expression = this.parseMaybeAssign();
}
return this.finishNode(node, "Decorator"); return this.finishNode(node, "Decorator");
} }