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

Skip to content

Commit 77fcf3d

Browse files
committed
JS: Support postfix "!" operator in templates
1 parent c08ba14 commit 77fcf3d

1 file changed

Lines changed: 13 additions & 0 deletions

File tree

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

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
import com.semmle.js.ast.Identifier;
1010
import com.semmle.js.ast.Position;
1111
import com.semmle.js.ast.SourceLocation;
12+
import com.semmle.ts.ast.NonNullAssertion;
1213

1314
/**
1415
* Parser for Angular template expressions, based on the JS parser with
@@ -47,4 +48,16 @@ protected Expression buildBinary(
4748
}
4849
return super.buildBinary(startPos, startLoc, left, right, op, logical);
4950
}
51+
52+
@Override
53+
protected Expression parseExprAtom(DestructuringErrors refDestructuringErrors) {
54+
// Parse postfix "!" operator
55+
Position startLoc = this.startLoc;
56+
Expression expr = super.parseExprAtom(refDestructuringErrors);
57+
if (this.type == TokenType.prefix && "!".equals(this.value)) {
58+
this.next(); // consume "!" token
59+
return finishNode(new NonNullAssertion(new SourceLocation(startLoc), expr));
60+
}
61+
return expr;
62+
}
5063
}

0 commit comments

Comments
 (0)