Skip to content

Commit ea563f8

Browse files
committed
JS: Rephrase dead store of local at declaration site
1 parent 6d10731 commit ea563f8

File tree

2 files changed

+17
-9
lines changed

2 files changed

+17
-9
lines changed

javascript/ql/src/Declarations/DeadStoreOfLocal.ql

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ predicate deadStoreOfLocal(VarDef vd, PurelyLocalVariable v) {
2626
not exists(SsaExplicitDefinition ssa | ssa.defines(vd, v))
2727
}
2828

29-
from VarDef dead, PurelyLocalVariable v // captured variables may be read by closures, so don't flag them
29+
from VarDef dead, PurelyLocalVariable v, string msg // captured variables may be read by closures, so don't flag them
3030
where
3131
deadStoreOfLocal(dead, v) and
3232
// the variable should be accessed somewhere; otherwise it will be flagged by UnusedVariable
@@ -51,5 +51,13 @@ where
5151
// don't flag exported variables
5252
not any(ES2015Module m).exportsAs(v, _) and
5353
// don't flag 'exports' assignments in closure modules
54-
not any(Closure::ClosureModule mod).getExportsVariable() = v
55-
select dead, "This definition of " + v.getName() + " is useless, since its value is never read."
54+
not any(Closure::ClosureModule mod).getExportsVariable() = v and
55+
(
56+
// To avoid confusion about the meaning of "definition" and "declaration" we avoid
57+
// the term "definition" when the alert location is a variable declaration.
58+
if dead instanceof VariableDeclarator then
59+
msg = "The initial value of " + v.getName() + " is unused, since it is always overwritten."
60+
else
61+
msg = "This definition of " + v.getName() + " is useless, since its value is never read."
62+
)
63+
select dead, msg
Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
| overload.ts:10:12:10:14 | baz | This definition of baz is useless, since its value is never read. |
2-
| tst2.js:26:9:26:14 | x = 23 | This definition of x is useless, since its value is never read. |
2+
| tst2.js:26:9:26:14 | x = 23 | The initial value of x is unused, since it is always overwritten. |
33
| tst2.js:28:9:28:14 | x = 42 | This definition of x is useless, since its value is never read. |
44
| tst3.js:2:1:2:36 | exports ... a: 23 } | This definition of exports is useless, since its value is never read. |
55
| tst3b.js:2:18:2:36 | exports = { a: 23 } | This definition of exports is useless, since its value is never read. |
66
| tst.js:6:2:6:7 | y = 23 | This definition of y is useless, since its value is never read. |
7-
| tst.js:13:6:13:11 | a = 23 | This definition of a is useless, since its value is never read. |
7+
| tst.js:13:6:13:11 | a = 23 | The initial value of a is unused, since it is always overwritten. |
88
| tst.js:13:14:13:19 | a = 42 | This definition of a is useless, since its value is never read. |
9-
| tst.js:45:6:45:11 | x = 23 | This definition of x is useless, since its value is never read. |
10-
| tst.js:51:6:51:11 | x = 23 | This definition of x is useless, since its value is never read. |
11-
| tst.js:132:7:132:13 | {x} = o | This definition of x is useless, since its value is never read. |
12-
| tst.js:162:6:162:14 | [x] = [0] | This definition of x is useless, since its value is never read. |
9+
| tst.js:45:6:45:11 | x = 23 | The initial value of x is unused, since it is always overwritten. |
10+
| tst.js:51:6:51:11 | x = 23 | The initial value of x is unused, since it is always overwritten. |
11+
| tst.js:132:7:132:13 | {x} = o | The initial value of x is unused, since it is always overwritten. |
12+
| tst.js:162:6:162:14 | [x] = [0] | The initial value of x is unused, since it is always overwritten. |

0 commit comments

Comments
 (0)