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

Skip to content

Commit 90c7713

Browse files
author
Esben Sparre Andreasen
committed
JS: make use of getUnderlyingValue in js/useless-assignment-to-local
1 parent ec1722c commit 90c7713

2 files changed

Lines changed: 2 additions & 5 deletions

File tree

javascript/ql/src/Declarations/DeadStoreOfLocal.ql

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,7 @@ predicate isDefaultInit(Expr e) {
3838
// initialising to an empty array or object literal, even if unnecessary,
3939
// can convey useful type information to the reader
4040
e.(ArrayExpr).getSize() = 0 or
41-
e.(ObjectExpr).getNumProperty() = 0 or
42-
// recursive case
43-
isDefaultInit(e.(AssignExpr).getRhs())
41+
e.(ObjectExpr).getNumProperty() = 0
4442
}
4543

4644
from VarDef dead, PurelyLocalVariable v // captured variables may be read by closures, so don't flag them
@@ -60,7 +58,7 @@ where deadStoreOfLocal(dead, v) and
6058
// don't flag overwrites with `null` or `undefined`
6159
not SyntacticConstants::isNullOrUndefined(dead.getSource()) and
6260
// don't flag default inits that are later overwritten
63-
not (isDefaultInit(dead.getSource()) and dead.isOverwritten(v)) and
61+
not (isDefaultInit(dead.getSource().(Expr).getUnderlyingValue()) and dead.isOverwritten(v)) and
6462
// don't flag assignments in externs
6563
not dead.(ASTNode).inExternsFile() and
6664
// don't flag exported variables

javascript/ql/test/query-tests/Declarations/DeadStoreOfLocal/DeadStoreOfLocal.expected

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,3 @@
77
| tst.js:45:6:45:11 | x = 23 | This definition of x is useless, since its value is never read. |
88
| tst.js:51:6:51:11 | x = 23 | This definition of x is useless, since its value is never read. |
99
| tst.js:132:7:132:13 | {x} = o | This definition of x is useless, since its value is never read. |
10-
| tst.js:158:11:158:21 | a = (x, -1) | This definition of a is useless, since its value is never read. |

0 commit comments

Comments
 (0)