From d0bf19681ab5150447af3108f1637fefa8fc6c43 Mon Sep 17 00:00:00 2001 From: Sebastian McKenzie Date: Fri, 10 Apr 2015 13:44:50 -0700 Subject: [PATCH] update to latest acorn --- src/expression.js | 15 ++++++++------- src/state.js | 3 +++ 2 files changed, 11 insertions(+), 7 deletions(-) diff --git a/src/expression.js b/src/expression.js index de02eb585b..2e6c59fb7d 100755 --- a/src/expression.js +++ b/src/expression.js @@ -93,13 +93,15 @@ pp.parseMaybeAssign = function(noIn, refShorthandDefaultPos, afterLeftParse) { failOnShorthandAssign = false } let start = this.markPosition() + if (this.type == tt.parenL || this.type == tt.name) + this.potentialArrowAt = this.start let left = this.parseMaybeConditional(noIn, refShorthandDefaultPos) if (afterLeftParse) left = afterLeftParse.call(this, left, start) if (this.type.isAssign) { let node = this.startNodeAt(start) node.operator = this.value node.left = this.type === tt.eq ? this.toAssignable(left) : left - refShorthandDefaultPos.start = 0; // reset because shorthand default was used correctly + refShorthandDefaultPos.start = 0 // reset because shorthand default was used correctly this.checkLVal(left) if (left.parenthesizedExpression) { if (left.type === "ObjectPattern") { @@ -240,7 +242,7 @@ pp.parseSubscripts = function(base, start, noCalls) { // or `{}`. pp.parseExprAtom = function(refShorthandDefaultPos) { - let node + let node, canBeArrow = this.potentialArrowAt == this.start switch (this.type) { case tt._this: case tt._super: @@ -302,9 +304,8 @@ pp.parseExprAtom = function(refShorthandDefaultPos) { } // - if (!this.canInsertSemicolon() && this.eat(tt.arrow)) { + if (canBeArrow && !this.canInsertSemicolon() && this.eat(tt.arrow)) return this.parseArrowExpression(this.startNodeAt(start), [id]) - } return id case tt.regexp: @@ -324,7 +325,7 @@ pp.parseExprAtom = function(refShorthandDefaultPos) { return this.finishNode(node, "Literal") case tt.parenL: - return this.parseParenAndDistinguishExpression() + return this.parseParenAndDistinguishExpression(null, null, canBeArrow) case tt.bracketL: node = this.startNode() @@ -378,7 +379,7 @@ pp.parseParenExpression = function() { return val } -pp.parseParenAndDistinguishExpression = function(start, isAsync) { +pp.parseParenAndDistinguishExpression = function(start, isAsync, canBeArrow) { start = start || this.markPosition() let val if (this.options.ecmaVersion >= 6) { @@ -407,7 +408,7 @@ pp.parseParenAndDistinguishExpression = function(start, isAsync) { let innerEnd = this.markPosition() this.expect(tt.parenR) - if (!this.canInsertSemicolon() && this.eat(tt.arrow)) { + if (canBeArrow && !this.canInsertSemicolon() && this.eat(tt.arrow)) { if (innerParenStart) this.unexpected(innerParenStart) return this.parseParenArrowList(start, exprList, isAsync) } diff --git a/src/state.js b/src/state.js index ecc2e77cb0..bebb6fdf31 100755 --- a/src/state.js +++ b/src/state.js @@ -46,6 +46,9 @@ export function Parser(options, input, startPos) { this.inModule = this.options.sourceType === "module" this.strict = this.options.strictMode === false ? false : this.inModule + // Used to signify the start of a potential arrow function + this.potentialArrowAt = -1 + // Flags to track whether we are in a function, a generator. this.inFunction = this.inGenerator = false // Labels in scope.