JS: make use of getUnderlyingValue in js/useless-assignment-to-local

This commit is contained in:
Esben Sparre Andreasen
2018-10-12 14:45:18 +02:00
parent ec1722c4db
commit 90c77134af
2 changed files with 2 additions and 5 deletions

View File

@@ -38,9 +38,7 @@ predicate isDefaultInit(Expr e) {
// initialising to an empty array or object literal, even if unnecessary,
// can convey useful type information to the reader
e.(ArrayExpr).getSize() = 0 or
e.(ObjectExpr).getNumProperty() = 0 or
// recursive case
isDefaultInit(e.(AssignExpr).getRhs())
e.(ObjectExpr).getNumProperty() = 0
}
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
// don't flag overwrites with `null` or `undefined`
not SyntacticConstants::isNullOrUndefined(dead.getSource()) and
// don't flag default inits that are later overwritten
not (isDefaultInit(dead.getSource()) and dead.isOverwritten(v)) and
not (isDefaultInit(dead.getSource().(Expr).getUnderlyingValue()) and dead.isOverwritten(v)) and
// don't flag assignments in externs
not dead.(ASTNode).inExternsFile() and
// don't flag exported variables

View File

@@ -7,4 +7,3 @@
| tst.js:45:6:45:11 | x = 23 | This definition of x is useless, since its value is never read. |
| tst.js:51:6:51:11 | x = 23 | This definition of x is useless, since its value is never read. |
| tst.js:132:7:132:13 | {x} = o | This definition of x is useless, since its value is never read. |
| tst.js:158:11:158:21 | a = (x, -1) | This definition of a is useless, since its value is never read. |