From 06afa0761bc77664ab87007b3638bed78f051135 Mon Sep 17 00:00:00 2001 From: Kevin Gibbons Date: Sat, 17 Jun 2017 13:23:30 +0530 Subject: [PATCH] Update decorator parsing to match current spec Refer to PR #353 --- src/parser/statement.js | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/src/parser/statement.js b/src/parser/statement.js index 610f7b4f53..82490e0779 100644 --- a/src/parser/statement.js +++ b/src/parser/statement.js @@ -175,9 +175,31 @@ export default class StatementParser extends ExpressionParser { if (!this.hasPlugin("decorators")) { this.unexpected(); } + const node = this.startNode(); this.next(); - node.expression = this.parseMaybeAssign(); + + 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"); + } + + 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"); }