mirror of
https://github.com/github/codeql.git
synced 2026-04-28 02:05:14 +02:00
better support for the &&=, ||=, and ??= operators
This commit is contained in:
@@ -1551,8 +1551,27 @@ public class CFGExtractor {
|
||||
|
||||
@Override
|
||||
public Void visit(AssignmentExpression nd, SuccessorInfo i) {
|
||||
visitAssign(nd, nd.getLeft(), nd.getRight());
|
||||
succ(nd, i.getGuardedSuccessors(nd));
|
||||
// `a &&= b` expands to `a || (a = b);`
|
||||
// The CFG is a conditional assignment, so we go through the assignment `nd` last.
|
||||
if ("&&=".equals(nd.getOperator()) || "||=".equals(nd.getOperator()) || "??=".equals(nd.getOperator())) {
|
||||
if ("&&=".equals(nd.getOperator())) {
|
||||
// from lhs to rhs on truthy. from lhs to false-branch on falsy.
|
||||
visit(nd.getLeft(), First.of(nd.getRight()), i.getSuccessors(false));
|
||||
} else if ("||=".equals(nd.getOperator())) {
|
||||
// from lhs to true-branch on truthy. from lhs to rhs on falsy.
|
||||
visit(nd.getLeft(), i.getSuccessors(true), First.of(nd.getRight()));
|
||||
} else { // "??="
|
||||
// the union of the above - truthyness is unknown.
|
||||
visit(nd.getLeft(), union(First.of(nd.getRight()), i.getAllSuccessors()), null);
|
||||
}
|
||||
|
||||
visit(nd.getRight(), First.of(nd), null); // from right to assignment.
|
||||
|
||||
succ(nd, i.getGuardedSuccessors(nd));
|
||||
} else {
|
||||
visitAssign(nd, nd.getLeft(), nd.getRight());
|
||||
succ(nd, i.getGuardedSuccessors(nd));
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
@@ -852,6 +852,9 @@ public class TypeScriptASTConverter {
|
||||
case ">>=":
|
||||
case "<<=":
|
||||
case ">>>=":
|
||||
case "??=":
|
||||
case "&&=":
|
||||
case "||=":
|
||||
return new AssignmentExpression(loc, operator, convertLValue(left), right);
|
||||
|
||||
default:
|
||||
|
||||
Reference in New Issue
Block a user