JS: add testss for js/trivial-conditional

This commit is contained in:
Esben Sparre Andreasen
2019-01-29 10:19:03 +01:00
parent a5aee9ed0f
commit 2683a9b43a
2 changed files with 39 additions and 0 deletions

View File

@@ -25,6 +25,8 @@
| UselessConditional.js:129:6:129:24 | constantUndefined() | This call to constantUndefined always evaluates to false. |
| UselessConditional.js:135:6:135:32 | constan ... ined1() | This call to constantFalseOrUndefined1 always evaluates to false. |
| UselessConditional.js:139:6:139:32 | constan ... ined2() | This call to constantFalseOrUndefined2 always evaluates to false. |
| UselessConditional.js:148:6:148:8 | p() | This call to p always evaluates to true. |
| UselessConditional.js:163:5:163:17 | findOrThrow() | This call to findOrThrow always evaluates to true. |
| UselessConditionalGood.js:58:12:58:13 | x2 | This use of variable 'x2' always evaluates to false. |
| UselessConditionalGood.js:69:12:69:13 | xy | This use of variable 'xy' always evaluates to false. |
| UselessConditionalGood.js:85:12:85:13 | xy | This use of variable 'xy' always evaluates to false. |

View File

@@ -140,4 +140,41 @@ async function awaitFlow(){
return;
});
(function () {
function p() {
return {};
}
if (p()) { // NOT OK
}
var v = p();
if (v) { // NOT OK
}
if (v) { // NOT OK, but not detected due to SSA limitations
}
});
(function() {
function findOrThrow() {
var e = find();
if (e) return e;
throw new Error();
}
if(findOrThrow()){ // NOT OK
}
var v = findOrThrow();
if (v) { // NOT OK
}
if (v) { // NOT OK, but not detected due to SSA limitations
}
});
(function () {
function f(){ return { v: unkown };}
f();
var { v } = f();
if (v) { // OK
}
});
// semmle-extractor-options: --experimental