Skip to content

Commit c8ded7e

Browse files
authored
Merge pull request github#6459 from erik-krogh/oreq
Approved by asgerf
2 parents 89ce25f + 01a202f commit c8ded7e

File tree

4 files changed

+33
-6
lines changed

4 files changed

+33
-6
lines changed

javascript/extractor/src/com/semmle/js/extractor/CFGExtractor.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1659,7 +1659,7 @@ public Void visit(MemberDefinition<?> nd, SuccessorInfo i) {
16591659

16601660
@Override
16611661
public Void visit(AssignmentExpression nd, SuccessorInfo i) {
1662-
// `a &&= b` expands to `a || (a = b);`
1662+
// `a &&= b` expands to `a && (a = b);`
16631663
// The CFG is a conditional assignment, so we go through the assignment `nd` last.
16641664
if ("&&=".equals(nd.getOperator()) || "||=".equals(nd.getOperator()) || "??=".equals(nd.getOperator())) {
16651665
if ("&&=".equals(nd.getOperator())) {
@@ -1673,7 +1673,7 @@ public Void visit(AssignmentExpression nd, SuccessorInfo i) {
16731673
visitWithSuccessors(nd.getLeft(), union(First.of(nd.getRight()), i.getAllSuccessors()));
16741674
}
16751675

1676-
visitWithSuccessors(nd.getRight(), First.of(nd)); // from right to assignment.
1676+
visitWithSuccessors(nd.getRight(), nd); // from right to assignment.
16771677

16781678
writeSuccessors(nd, i.getGuardedSuccessors(nd));
16791679
} else {

javascript/extractor/tests/es2021/output/trap/assign.js.trap

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -556,7 +556,7 @@ hasLocation(#20168,#20109)
556556
successor(#20161,#20164)
557557
successor(#20164,#20165)
558558
successor(#20164,#20168)
559-
successor(#20165,#20164)
559+
successor(#20165,#20162)
560560
successor(#20162,#20168)
561561
successor(#20156,#20159)
562562
#20169=*
@@ -569,7 +569,7 @@ hasLocation(#20170,#20093)
569569
successor(#20170,#20160)
570570
successor(#20159,#20169)
571571
successor(#20159,#20170)
572-
successor(#20160,#20159)
572+
successor(#20160,#20157)
573573
successor(#20157,#20161)
574574
successor(#20151,#20154)
575575
#20171=*
@@ -582,7 +582,7 @@ hasLocation(#20172,#20085)
582582
successor(#20172,#20156)
583583
successor(#20154,#20171)
584584
successor(#20154,#20172)
585-
successor(#20155,#20154)
585+
successor(#20155,#20152)
586586
successor(#20152,#20156)
587587
successor(#20141,#20147)
588588
successor(#20150,#20143)
@@ -601,7 +601,7 @@ hasLocation(#20174,#20063)
601601
successor(#20174,#20134)
602602
successor(#20139,#20173)
603603
successor(#20139,#20174)
604-
successor(#20140,#20139)
604+
successor(#20140,#20137)
605605
successor(#20137,#20134)
606606
successor(#20136,#20139)
607607
successor(#20134,#20141)

javascript/ql/src/semmle/javascript/dataflow/DataFlow.qll

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1495,6 +1495,16 @@ module DataFlow {
14951495
predExpr = succExpr.(NonNullAssertion).getExpression()
14961496
or
14971497
predExpr = succExpr.(ExpressionWithTypeArguments).getExpression()
1498+
or
1499+
(
1500+
succExpr instanceof AssignLogOrExpr or
1501+
succExpr instanceof AssignLogAndExpr or
1502+
succExpr instanceof AssignNullishCoalescingExpr
1503+
) and
1504+
(
1505+
predExpr = succExpr.(CompoundAssignExpr).getLhs() or
1506+
predExpr = succExpr.(CompoundAssignExpr).getRhs()
1507+
)
14981508
)
14991509
or
15001510
// flow from 'this' parameter into 'this' expressions
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
function f() {
2+
let foo;
3+
if (bar) foo ||= [];
4+
if (foo);
5+
};
6+
7+
function g() {
8+
let foo;
9+
if (bar) foo ??= [];
10+
if (foo);
11+
};
12+
13+
function h() {
14+
let foo = true;
15+
if (bar) foo &&= false;
16+
if (foo);
17+
}

0 commit comments

Comments
 (0)