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

Skip to content

Commit 8af501d

Browse files
author
Esben Sparre Andreasen
committed
JS: avoid double reporting dead code with js/unused-variable
1 parent 91dccc3 commit 8af501d

2 files changed

Lines changed: 10 additions & 2 deletions

File tree

javascript/ql/src/Declarations/UnusedVariable.ql

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -190,6 +190,10 @@ predicate unusedImports(ImportVarDeclProvider provider, string msg) {
190190

191191
from ASTNode sel, string msg
192192
where
193-
unusedNonImports(sel, msg) or
194-
unusedImports(sel, msg)
193+
(
194+
unusedNonImports(sel, msg) or
195+
unusedImports(sel, msg)
196+
) and
197+
// avoid reporting if the definition is unreachable
198+
sel.getFirstControlFlowNode().getBasicBlock() instanceof ReachableBasicBlock
195199
select sel, msg
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
(function(){
2+
throw 42;
3+
var x = 42;
4+
});

0 commit comments

Comments
 (0)