Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,13 @@ protected Expression buildBinary(
boolean logical) {
// Angular pipe expression: `x|f:a` is desugared to `f(x, a)`
if (op.equals("|")) {
DestructuringErrors refDestructuringErrors = new DestructuringErrors();
List<Expression> arguments = new ArrayList<>();
arguments.add(left);
while (this.type == TokenType.colon) {
this.next();
int argStartPos = this.pos;
Position argStartLocation = this.curPosition();
Expression arg = parseMaybeUnary(refDestructuringErrors, false);
Expression arg = parseMaybeUnary(false);
arguments.add(parseExprOp(arg, argStartPos, argStartLocation, TokenType.plusMin.binop, true));
}
SourceLocation loc = new SourceLocation(startLoc);
Expand All @@ -50,10 +49,10 @@ protected Expression buildBinary(
}

@Override
protected Expression parseExprAtom(DestructuringErrors refDestructuringErrors) {
protected Expression parseExprAtom() {
// Parse postfix "!" operator
Position startLoc = this.startLoc;
Expression expr = super.parseExprAtom(refDestructuringErrors);
Expression expr = super.parseExprAtom();
if (this.type == TokenType.prefix && "!".equals(this.value)) {
this.next(); // consume "!" token
return finishNode(new NonNullAssertion(new SourceLocation(startLoc), expr));
Expand Down
39 changes: 18 additions & 21 deletions javascript/extractor/src/com/semmle/jcorn/CustomParser.java
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ protected CatchClause parseCatchClause(Position startLoc) {
if (this.eat(TokenType.parenL)) {
param = this.parseBindingAtom();
this.checkLVal(param, true, null);
if (this.eat(TokenType._if)) guard = this.parseExpression(false, null);
if (this.eat(TokenType._if)) guard = this.parseExpression(false);
this.expect(TokenType.parenR);
} else if (!options.esnext()) {
this.unexpected();
Expand Down Expand Up @@ -123,7 +123,7 @@ protected Statement parseVarStatement(Position startLoc, String kind) {
}

@Override
protected Expression parseExprAtom(DestructuringErrors refDestructuringErrors) {
protected Expression parseExprAtom() {
Position startLoc = this.startLoc;
if (options.mozExtensions() && this.isContextual("let")) {
this.next();
Expand All @@ -141,9 +141,9 @@ protected Expression parseExprAtom(DestructuringErrors refDestructuringErrors) {
if (this.type == TokenType.comma
|| this.type == TokenType.bracketR
|| this.type == TokenType.ellipsis) {
elements = this.parseExprList(TokenType.bracketR, true, true, refDestructuringErrors);
elements = this.parseExprList(TokenType.bracketR, true, true);
} else {
Expression firstExpr = this.parseMaybeAssign(false, refDestructuringErrors, null);
Expression firstExpr = this.parseMaybeAssign(false, null);
// check whether this is a postfix array comprehension
if (this.type == TokenType._for || this.type == TokenType._if) {
ComprehensionExpression c = this.parseComprehension(startLoc, false, firstExpr);
Expand All @@ -154,7 +154,7 @@ protected Expression parseExprAtom(DestructuringErrors refDestructuringErrors) {
elements = new ArrayList<Expression>();
elements.add(firstExpr);
elements.addAll(
this.parseExprList(TokenType.bracketR, true, true, refDestructuringErrors));
this.parseExprList(TokenType.bracketR, true, true));
}
}
return this.finishNode(new ArrayExpression(new SourceLocation(startLoc), elements));
Expand All @@ -164,7 +164,7 @@ protected Expression parseExprAtom(DestructuringErrors refDestructuringErrors) {
Identifier buildinName = this.parseIdent(true);
Identifier name = this.finishNode(new Identifier(new SourceLocation(startLoc), "%" + buildinName.getName()));
this.expect(TokenType.parenL);
List<Expression> args = this.parseExprList(TokenType.parenR, false, false, null);
List<Expression> args = this.parseExprList(TokenType.parenR, false, false);
CallExpression node =
new CallExpression(
new SourceLocation(startLoc), name, new ArrayList<>(), args, false, false);
Expand All @@ -184,7 +184,7 @@ protected Expression parseExprAtom(DestructuringErrors refDestructuringErrors) {
}
return attr;
} else {
return super.parseExprAtom(refDestructuringErrors);
return super.parseExprAtom();
}
}

Expand All @@ -197,7 +197,7 @@ protected Node parseLetExpression(Position startLoc, boolean maybeStatement) {
if (this.type == TokenType.braceL) {
if (!maybeStatement) {
// must be the start of an object literal
Expression body = this.parseObj(false, null);
Expression body = this.parseObj(false);
return this.finishNode(
new LetExpression(new SourceLocation(startLoc), decl.getDeclarations(), body));
}
Expand All @@ -212,7 +212,7 @@ protected Node parseLetExpression(Position startLoc, boolean maybeStatement) {
return this.finishNode(
new LetStatement(new SourceLocation(startLoc), decl.getDeclarations(), body));
} else {
Expression body = this.parseExpression(false, null);
Expression body = this.parseExpression(false);
return this.finishNode(
new LetExpression(new SourceLocation(startLoc), decl.getDeclarations(), body));
}
Expand Down Expand Up @@ -283,13 +283,12 @@ private boolean eatDoubleColon() {

// accept `yield` in non-generator functions
@Override
protected Expression parseMaybeAssign(
boolean noIn, DestructuringErrors refDestructuringErrors, AfterLeftParse afterLeftParse) {
protected Expression parseMaybeAssign(boolean noIn, AfterLeftParse afterLeftParse) {
if (options.mozExtensions() && isContextual("yield")) {
if (!this.inFunction) this.raise(this.startLoc, "Yield not in function");
return this.parseYield();
}
return super.parseMaybeAssign(noIn, refDestructuringErrors, afterLeftParse);
return super.parseMaybeAssign(noIn, afterLeftParse);
}

// add parsing of comprehensions
Expand All @@ -309,12 +308,12 @@ protected ComprehensionExpression parseComprehension(
} else {
this.expect(TokenType._in);
}
Expression right = this.parseExpression(false, null);
Expression right = this.parseExpression(false);
this.expect(TokenType.parenR);
blocks.add(this.finishNode(new ComprehensionBlock(blockStart, (IPattern) left, right, of)));
}
Expression filter = this.eat(TokenType._if) ? this.parseParenExpression() : null;
if (body == null) body = this.parseExpression(false, null);
if (body == null) body = this.parseExpression(false);

return new ComprehensionExpression(
new SourceLocation(startLoc), body, blocks, filter, isGenerator);
Expand Down Expand Up @@ -353,13 +352,11 @@ protected Expression parseParenAndDistinguishExpression(boolean canBeArrow) {

@Override
protected boolean parseParenthesisedExpression(
DestructuringErrors refDestructuringErrors,
boolean allowTrailingComma,
ParenthesisedExpressions parenExprs,
boolean first) {
boolean cont =
super.parseParenthesisedExpression(
refDestructuringErrors, allowTrailingComma, parenExprs, first);
super.parseParenthesisedExpression(allowTrailingComma, parenExprs, first);
if (options.mozExtensions() && parenExprs.exprList.size() == 1 && this.type == TokenType._for) {
Expression body = parenExprs.exprList.remove(0);
ComprehensionExpression c = parseComprehension(body.getLoc().getStart(), true, body);
Expand Down Expand Up @@ -399,7 +396,7 @@ protected Expression parseNew() {
&& options.mozExtensions()
&& !canInsertSemicolon()
&& this.type == TokenType.braceL) {
((NewExpression) res).getArguments().add(this.parseObj(false, null));
((NewExpression) res).getArguments().add(this.parseObj(false));
res = this.finishNode(res);
}
return res;
Expand Down Expand Up @@ -465,7 +462,7 @@ protected Pair<Expression, Boolean> parseSubscript(
if (options.e4x() && this.eat(TokenType.dot)) {
SourceLocation start = new SourceLocation(startLoc);
if (this.eat(TokenType.parenL)) {
Expression filter = parseExpression(false, null);
Expression filter = parseExpression(false);
this.expect(TokenType.parenR);
return Pair.make(this.finishNode(new XMLFilterExpression(start, base, filter)), true);
}
Expand Down Expand Up @@ -515,7 +512,7 @@ protected Expression parsePropertySelector(SourceLocation start) {
*/
protected Expression parseAttributeIdentifier(SourceLocation start) {
if (this.eat(TokenType.bracketL)) {
Expression idx = parseExpression(false, null);
Expression idx = parseExpression(false);
this.expect(TokenType.bracketR);
return this.finishNode(new XMLAttributeSelector(start, idx, true));
} else {
Expand All @@ -533,7 +530,7 @@ protected Expression parseDecoratorBody() {
// followed by a right bracket, which will later be converted by
// `decoratorToAttributeSelector` below
List<Expression> elements = new ArrayList<>();
elements.add(parseExpression(false, null));
elements.add(parseExpression(false));
this.expect(TokenType.bracketR);
return this.finishNode(new ArrayExpression(start, elements));
}
Expand Down
23 changes: 10 additions & 13 deletions javascript/extractor/src/com/semmle/jcorn/ESNextParser.java
Original file line number Diff line number Diff line change
Expand Up @@ -59,17 +59,14 @@ public ESNextParser(Options options, String input, int startPos) {
*/

@Override
protected Property parseProperty(
boolean isPattern,
DestructuringErrors refDestructuringErrors,
Map<String, PropInfo> propHash) {
protected Property parseProperty(boolean isPattern, Map<String, PropInfo> propHash) {
Position start = this.startLoc;

List<Decorator> decorators = parseDecorators();

Property prop = null;
if (this.type == TokenType.ellipsis) {
SpreadElement spread = this.parseSpread(null);
SpreadElement spread = this.parseSpread();
Expression val;
if (isPattern) val = new RestElement(spread.getLoc(), spread.getArgument());
else val = spread;
Expand All @@ -79,7 +76,7 @@ protected Property parseProperty(
new SourceLocation(start), null, val, Property.Kind.INIT.name(), false, false));
}

if (prop == null) prop = super.parseProperty(isPattern, refDestructuringErrors, propHash);
if (prop == null) prop = super.parseProperty(isPattern, propHash);

prop.addDecorators(decorators);

Expand Down Expand Up @@ -129,7 +126,7 @@ protected FieldDefinition parseFieldDefinition(PropertyInfo pi, boolean isStatic
this.next();
boolean oldInFunc = this.inFunction;
this.inFunction = true;
value = parseMaybeAssign(false, null, null);
value = parseMaybeAssign(false, null);
this.inFunction = oldInFunc;
}
this.semicolon();
Expand Down Expand Up @@ -220,7 +217,7 @@ protected Statement parseStatement(boolean declaration, boolean topLevel, Set<St
}

@Override
protected Expression parseExprAtom(DestructuringErrors refDestructuringErrors) {
protected Expression parseExprAtom() {
if (this.type == at) {
List<Decorator> decorators = parseDecorators();
ClassExpression ce = (ClassExpression) this.parseClass(startLoc, false);
Expand All @@ -232,7 +229,7 @@ protected Expression parseExprAtom(DestructuringErrors refDestructuringErrors) {
this.next();
int innerStart = this.start;
Position innerStartLoc = this.startLoc;
Expression callee = parseSubscripts(parseExprAtom(null), innerStart, innerStartLoc, true);
Expression callee = parseSubscripts(parseExprAtom(), innerStart, innerStartLoc, true);
if (!(callee instanceof MemberExpression))
this.raiseRecoverable(callee, "Binding should be performed on a member expression.");
return this.finishNode(new BindExpression(startLoc, null, callee));
Expand All @@ -246,7 +243,7 @@ protected Expression parseExprAtom(DestructuringErrors refDestructuringErrors) {
this.expect(TokenType.parenL);
return parseDynamicImport(startLoc);
}
return super.parseExprAtom(refDestructuringErrors);
return super.parseExprAtom();
}

@Override
Expand Down Expand Up @@ -373,7 +370,7 @@ private boolean functionBind() {
protected Pair<Expression, Boolean> parseSubscript(
Expression base, Position startLoc, boolean noCalls) {
if (!noCalls && this.eat(doubleColon)) {
Expression callee = parseSubscripts(parseExprAtom(null), this.start, this.startLoc, true);
Expression callee = parseSubscripts(parseExprAtom(), this.start, this.startLoc, true);
BindExpression bind = new BindExpression(new SourceLocation(startLoc), base, callee);
return Pair.make(this.finishNode(bind), true);
}
Expand Down Expand Up @@ -438,11 +435,11 @@ private MetaProperty parseImportMeta(Position loc) {
* already been consumed.
*/
private DynamicImport parseDynamicImport(Position startLoc) {
Expression source = parseMaybeAssign(false, null, null);
Expression source = parseMaybeAssign(false, null);
Expression attributes = null;
if (this.eat(TokenType.comma)) {
if (this.type != TokenType.parenR) { // Skip if the comma was a trailing comma
attributes = this.parseMaybeAssign(false, null, null);
attributes = this.parseMaybeAssign(false, null);
this.eat(TokenType.comma); // Allow trailing comma
}
}
Expand Down
Loading
Loading