Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit bb93cef

Browse files
author
Max Schaefer
committed
JavaScript: Refactor parsing of parenthesised expressions.
1 parent 92c8501 commit bb93cef

1 file changed

Lines changed: 21 additions & 14 deletions

File tree

javascript/extractor/src/com/semmle/jcorn/Parser.java

Lines changed: 21 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1691,27 +1691,34 @@ protected ParenthesisedExpressions parseParenthesisedExpressions(DestructuringEr
16911691
first = false;
16921692
else
16931693
this.expect(TokenType.comma);
1694-
if (allowTrailingComma && this.afterTrailingComma(TokenType.parenR, true)) {
1695-
parenExprs.lastIsComma = true;
1694+
if (!parseParenthesisedExpression(refDestructuringErrors, allowTrailingComma, parenExprs, first))
16961695
break;
1697-
} else if (this.type == TokenType.ellipsis) {
1698-
parenExprs.spreadStart = this.start;
1699-
parenExprs.exprList.add(this.parseParenItem(this.parseRest(false), -1, null));
1700-
if (this.type == TokenType.comma)
1701-
this.raise(this.startLoc, "Comma is not permitted after the rest element");
1702-
break;
1703-
} else {
1704-
if (this.type == TokenType.parenL && parenExprs.innerParenStart == 0) {
1705-
parenExprs.innerParenStart = this.start;
1706-
}
1707-
parenExprs.exprList.add(this.parseMaybeAssign(false, refDestructuringErrors, this::parseParenItem));
1708-
}
17091696
}
17101697
parenExprs.endLoc = this.startLoc;
17111698
this.expect(TokenType.parenR);
17121699
return parenExprs;
17131700
}
17141701

1702+
protected boolean parseParenthesisedExpression(DestructuringErrors refDestructuringErrors,
1703+
boolean allowTrailingComma, ParenthesisedExpressions parenExprs, boolean first) {
1704+
if (allowTrailingComma && this.afterTrailingComma(TokenType.parenR, true)) {
1705+
parenExprs.lastIsComma = true;
1706+
return false;
1707+
} else if (this.type == TokenType.ellipsis) {
1708+
parenExprs.spreadStart = this.start;
1709+
parenExprs.exprList.add(this.parseParenItem(this.parseRest(false), -1, null));
1710+
if (this.type == TokenType.comma)
1711+
this.raise(this.startLoc, "Comma is not permitted after the rest element");
1712+
return false;
1713+
} else {
1714+
if (this.type == TokenType.parenL && parenExprs.innerParenStart == 0) {
1715+
parenExprs.innerParenStart = this.start;
1716+
}
1717+
parenExprs.exprList.add(this.parseMaybeAssign(false, refDestructuringErrors, this::parseParenItem));
1718+
}
1719+
return true;
1720+
}
1721+
17151722
protected Expression parseParenItem(Expression left, int startPos, Position startLoc) {
17161723
return left;
17171724
}

0 commit comments

Comments
 (0)