File tree Expand file tree Collapse file tree 4 files changed +33
-6
lines changed
src/semmle/javascript/dataflow
test/query-tests/Statements/UselessConditional Expand file tree Collapse file tree 4 files changed +33
-6
lines changed Original file line number Diff line number Diff line change @@ -1659,7 +1659,7 @@ public Void visit(MemberDefinition<?> nd, SuccessorInfo i) {
1659
1659
1660
1660
@ Override
1661
1661
public Void visit (AssignmentExpression nd , SuccessorInfo i ) {
1662
- // `a &&= b` expands to `a || (a = b);`
1662
+ // `a &&= b` expands to `a && (a = b);`
1663
1663
// The CFG is a conditional assignment, so we go through the assignment `nd` last.
1664
1664
if ("&&=" .equals (nd .getOperator ()) || "||=" .equals (nd .getOperator ()) || "??=" .equals (nd .getOperator ())) {
1665
1665
if ("&&=" .equals (nd .getOperator ())) {
@@ -1673,7 +1673,7 @@ public Void visit(AssignmentExpression nd, SuccessorInfo i) {
1673
1673
visitWithSuccessors (nd .getLeft (), union (First .of (nd .getRight ()), i .getAllSuccessors ()));
1674
1674
}
1675
1675
1676
- visitWithSuccessors (nd .getRight (), First . of ( nd ) ); // from right to assignment.
1676
+ visitWithSuccessors (nd .getRight (), nd ); // from right to assignment.
1677
1677
1678
1678
writeSuccessors (nd , i .getGuardedSuccessors (nd ));
1679
1679
} else {
Original file line number Diff line number Diff line change @@ -556,7 +556,7 @@ hasLocation(#20168,#20109)
556
556
successor(#20161,#20164)
557
557
successor(#20164,#20165)
558
558
successor(#20164,#20168)
559
- successor(#20165,#20164 )
559
+ successor(#20165,#20162 )
560
560
successor(#20162,#20168)
561
561
successor(#20156,#20159)
562
562
#20169=*
@@ -569,7 +569,7 @@ hasLocation(#20170,#20093)
569
569
successor(#20170,#20160)
570
570
successor(#20159,#20169)
571
571
successor(#20159,#20170)
572
- successor(#20160,#20159 )
572
+ successor(#20160,#20157 )
573
573
successor(#20157,#20161)
574
574
successor(#20151,#20154)
575
575
#20171=*
@@ -582,7 +582,7 @@ hasLocation(#20172,#20085)
582
582
successor(#20172,#20156)
583
583
successor(#20154,#20171)
584
584
successor(#20154,#20172)
585
- successor(#20155,#20154 )
585
+ successor(#20155,#20152 )
586
586
successor(#20152,#20156)
587
587
successor(#20141,#20147)
588
588
successor(#20150,#20143)
@@ -601,7 +601,7 @@ hasLocation(#20174,#20063)
601
601
successor(#20174,#20134)
602
602
successor(#20139,#20173)
603
603
successor(#20139,#20174)
604
- successor(#20140,#20139 )
604
+ successor(#20140,#20137 )
605
605
successor(#20137,#20134)
606
606
successor(#20136,#20139)
607
607
successor(#20134,#20141)
Original file line number Diff line number Diff line change @@ -1495,6 +1495,16 @@ module DataFlow {
1495
1495
predExpr = succExpr .( NonNullAssertion ) .getExpression ( )
1496
1496
or
1497
1497
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
+ )
1498
1508
)
1499
1509
or
1500
1510
// flow from 'this' parameter into 'this' expressions
Original file line number Diff line number Diff line change
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
+ }
You can’t perform that action at this time.
0 commit comments