From a24dc6e6301e28c8b333524b958846b15d6353ee Mon Sep 17 00:00:00 2001 From: Peeyush Kushwaha Date: Sat, 17 Jun 2017 13:25:21 +0530 Subject: [PATCH] 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 --- src/parser/statement.js | 44 ++++++++++++++++++++++------------------- 1 file changed, 24 insertions(+), 20 deletions(-) diff --git a/src/parser/statement.js b/src/parser/statement.js index 82490e0779..7731c7a9f3 100644 --- a/src/parser/statement.js +++ b/src/parser/statement.js @@ -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"); }