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

Skip to content

Commit 2683a9b

Browse files
author
Esben Sparre Andreasen
committed
JS: add testss for js/trivial-conditional
1 parent a5aee9e commit 2683a9b

2 files changed

Lines changed: 39 additions & 0 deletions

File tree

javascript/ql/test/query-tests/Statements/UselessConditional/UselessConditional.expected

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@
2525
| UselessConditional.js:129:6:129:24 | constantUndefined() | This call to constantUndefined always evaluates to false. |
2626
| UselessConditional.js:135:6:135:32 | constan ... ined1() | This call to constantFalseOrUndefined1 always evaluates to false. |
2727
| UselessConditional.js:139:6:139:32 | constan ... ined2() | This call to constantFalseOrUndefined2 always evaluates to false. |
28+
| UselessConditional.js:148:6:148:8 | p() | This call to p always evaluates to true. |
29+
| UselessConditional.js:163:5:163:17 | findOrThrow() | This call to findOrThrow always evaluates to true. |
2830
| UselessConditionalGood.js:58:12:58:13 | x2 | This use of variable 'x2' always evaluates to false. |
2931
| UselessConditionalGood.js:69:12:69:13 | xy | This use of variable 'xy' always evaluates to false. |
3032
| UselessConditionalGood.js:85:12:85:13 | xy | This use of variable 'xy' always evaluates to false. |

javascript/ql/test/query-tests/Statements/UselessConditional/UselessConditional.js

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,4 +140,41 @@ async function awaitFlow(){
140140
return;
141141

142142
});
143+
144+
(function () {
145+
function p() {
146+
return {};
147+
}
148+
if (p()) { // NOT OK
149+
}
150+
var v = p();
151+
if (v) { // NOT OK
152+
}
153+
if (v) { // NOT OK, but not detected due to SSA limitations
154+
}
155+
});
156+
157+
(function() {
158+
function findOrThrow() {
159+
var e = find();
160+
if (e) return e;
161+
throw new Error();
162+
}
163+
if(findOrThrow()){ // NOT OK
164+
}
165+
var v = findOrThrow();
166+
if (v) { // NOT OK
167+
}
168+
if (v) { // NOT OK, but not detected due to SSA limitations
169+
}
170+
});
171+
172+
(function () {
173+
function f(){ return { v: unkown };}
174+
f();
175+
var { v } = f();
176+
if (v) { // OK
177+
}
178+
});
179+
143180
// semmle-extractor-options: --experimental

0 commit comments

Comments
 (0)