File tree Expand file tree Collapse file tree 3 files changed +20
-12
lines changed
test/query-tests/Expressions/ExprHasNoEffect Expand file tree Collapse file tree 3 files changed +20
-12
lines changed Original file line number Diff line number Diff line change @@ -129,6 +129,20 @@ predicate noSideEffects(Expr e) {
129
129
)
130
130
}
131
131
132
+ /**
133
+ * Holds if `e` is a compound expression that may contain sub-expressions with side effects.
134
+ * We should not flag these directly as useless since we want to flag only the innermost
135
+ * expressions that actually have no effect.
136
+ */
137
+ predicate isCompoundExpression ( Expr e ) {
138
+ e instanceof LogicalBinaryExpr
139
+ or
140
+ e instanceof SeqExpr
141
+ or
142
+ e instanceof ParExpr and
143
+ not e .stripParens ( ) instanceof FunctionExpr
144
+ }
145
+
132
146
/**
133
147
* Holds if the expression `e` should be reported as having no effect.
134
148
*/
@@ -145,6 +159,7 @@ predicate hasNoEffect(Expr e) {
145
159
not isDeclaration ( e ) and
146
160
// exclude DOM properties, which sometimes have magical auto-update properties
147
161
not isDomProperty ( e .( PropAccess ) .getPropertyName ( ) ) and
162
+ not isCompoundExpression ( e ) and
148
163
// exclude xUnit.js annotations
149
164
not e instanceof XUnitAnnotation and
150
165
// exclude common patterns that are most likely intentional
Original file line number Diff line number Diff line change 1
- | dom.js:2:5:2:30 | a.clien ... ientTop | This expression has no effect. |
2
- | dom.js:2:5:2:50 | a.clien ... === !0 | This expression has no effect. |
3
1
| dom.js:2:33:2:50 | a.clientTop === !0 | This expression has no effect. |
4
- | dom.js:3:5:3:20 | a && a.clientTop | This expression has no effect. |
5
- | dom.js:4:5:4:28 | a.clien ... ientTop | This expression has no effect. |
6
- | dom.js:5:18:5:43 | a.clien ... ientTop | This expression has no effect. |
7
- | dom.js:6:18:6:63 | b && (b ... entTop) | This expression has no effect. |
8
- | dom.js:6:23:6:63 | (b.clie ... entTop) | This expression has no effect. |
9
2
| try.js:22:9:22:26 | x.ordinaryProperty | This expression has no effect. |
10
3
| tst2.js:2:4:2:4 | 0 | This expression has no effect. |
11
4
| tst.js:3:1:3:2 | 23 | This expression has no effect. |
Original file line number Diff line number Diff line change 1
1
function f ( ) {
2
- a . clientTop && a . clientTop , a . clientTop === ! 0 ; // $Alert
3
- a && a . clientTop ; // $SPURIOUS:Alert
4
- a . clientTop , a . clientTop ; // $SPURIOUS:Alert
5
- if ( a ) return a . clientTop && a . clientTop , a . clientTop === ! 0 // $SPURIOUS:Alert
6
- if ( b ) return b && ( b . clientTop , b . clientTop && b . clientTop ) , null // $SPURIOUS:Alert
2
+ a . clientTop && a . clientTop , a . clientTop === ! 0 ; //$Alert
3
+ a && a . clientTop ;
4
+ a . clientTop , a . clientTop ;
5
+ if ( a ) return a . clientTop && a . clientTop , a . clientTop === ! 0 ;
6
+ if ( b ) return b && ( b . clientTop , b . clientTop && b . clientTop ) , null ;
7
7
}
You can’t perform that action at this time.
0 commit comments