JS: Support postfix "!" operator in templates

This commit is contained in:
Asger Feldthaus
2020-12-11 14:40:44 +00:00
parent c08ba1416d
commit 77fcf3d8a2

View File

@@ -9,6 +9,7 @@ import com.semmle.js.ast.Expression;
import com.semmle.js.ast.Identifier;
import com.semmle.js.ast.Position;
import com.semmle.js.ast.SourceLocation;
import com.semmle.ts.ast.NonNullAssertion;
/**
* Parser for Angular template expressions, based on the JS parser with
@@ -47,4 +48,16 @@ public class AngularExpressionParser extends CustomParser {
}
return super.buildBinary(startPos, startLoc, left, right, op, logical);
}
@Override
protected Expression parseExprAtom(DestructuringErrors refDestructuringErrors) {
// Parse postfix "!" operator
Position startLoc = this.startLoc;
Expression expr = super.parseExprAtom(refDestructuringErrors);
if (this.type == TokenType.prefix && "!".equals(this.value)) {
this.next(); // consume "!" token
return finishNode(new NonNullAssertion(new SourceLocation(startLoc), expr));
}
return expr;
}
}