Skip to content

Commit dc774e0

Browse files
authored
Merge pull request github#3166 from erik-krogh/DeadLocal
Approved by asgerf
2 parents 604731b + 45797dc commit dc774e0

File tree

3 files changed

+19
-8
lines changed

3 files changed

+19
-8
lines changed

javascript/ql/src/Declarations/DeadStoreOfLocal.ql

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,8 +63,10 @@ where
6363
(
6464
// To avoid confusion about the meaning of "definition" and "declaration" we avoid
6565
// the term "definition" when the alert location is a variable declaration.
66-
if dead instanceof VariableDeclarator
66+
if
67+
dead instanceof VariableDeclarator and
68+
not exists(SsaImplicitInit init | init.getVariable().getSourceVariable() = v) // the variable is dead at the hoisted implicit initialization.
6769
then msg = "The initial value of " + v.getName() + " is unused, since it is always overwritten."
68-
else msg = "This definition of " + v.getName() + " is useless, since its value is never read."
70+
else msg = "The value assigned to " + v.getName() + " here is unused."
6971
)
7072
select dead, msg
Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
1-
| overload.ts:10:12:10:14 | baz | This definition of baz is useless, since its value is never read. |
1+
| overload.ts:10:12:10:14 | baz | The value assigned to baz here is unused. |
22
| tst2.js:26:9:26:14 | x = 23 | The initial value of x is unused, since it is always overwritten. |
3-
| tst2.js:28:9:28:14 | x = 42 | This definition of x is useless, since its value is never read. |
4-
| tst3.js:2:1:2:36 | exports ... a: 23 } | This definition of exports is useless, since its value is never read. |
5-
| tst3b.js:2:18:2:36 | exports = { a: 23 } | This definition of exports is useless, since its value is never read. |
6-
| tst.js:6:2:6:7 | y = 23 | This definition of y is useless, since its value is never read. |
3+
| tst2.js:28:9:28:14 | x = 42 | The value assigned to x here is unused. |
4+
| tst3.js:2:1:2:36 | exports ... a: 23 } | The value assigned to exports here is unused. |
5+
| tst3b.js:2:18:2:36 | exports = { a: 23 } | The value assigned to exports here is unused. |
6+
| tst.js:6:2:6:7 | y = 23 | The value assigned to y here is unused. |
77
| tst.js:13:6:13:11 | a = 23 | The initial value of a is unused, since it is always overwritten. |
8-
| tst.js:13:14:13:19 | a = 42 | This definition of a is useless, since its value is never read. |
8+
| tst.js:13:14:13:19 | a = 42 | The value assigned to a here is unused. |
99
| tst.js:45:6:45:11 | x = 23 | The initial value of x is unused, since it is always overwritten. |
1010
| tst.js:51:6:51:11 | x = 23 | The initial value of x is unused, since it is always overwritten. |
1111
| tst.js:132:7:132:13 | {x} = o | The initial value of x is unused, since it is always overwritten. |
1212
| tst.js:162:6:162:14 | [x] = [0] | The initial value of x is unused, since it is always overwritten. |
13+
| tst.js:172:7:172:17 | nSign = foo | The value assigned to nSign here is unused. |

javascript/ql/test/query-tests/Declarations/DeadStoreOfLocal/tst.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,3 +166,11 @@ function v() {
166166
x;
167167
y;
168168
});
169+
170+
(function() {
171+
if (something()) {
172+
var nSign = foo;
173+
} else {
174+
console.log(nSign);
175+
}
176+
})()

0 commit comments

Comments
 (0)