mirror of
https://github.com/github/codeql.git
synced 2026-04-30 11:15:13 +02:00
JS: support noop parentheses in js/useless-assignment-to-local
The syntatic recognizer `isNullOrUndef` did not handle expressions that were wrapped in parentheses. This eliminates some results here: https://lgtm.com/projects/g/vuejs/vue/alerts?mode=tree&ruleFocus=7900088
This commit is contained in:
@@ -33,12 +33,15 @@ predicate deadStoreOfLocal(VarDef vd, PurelyLocalVariable v) {
|
||||
* is itself an expression evaluating to `null` or `undefined`.
|
||||
*/
|
||||
predicate isNullOrUndef(Expr e) {
|
||||
// `null` or `undefined`
|
||||
e instanceof NullLiteral or
|
||||
e.(VarAccess).getName() = "undefined" or
|
||||
e instanceof VoidExpr or
|
||||
// recursive case to catch multi-assignments of the form `x = y = null`
|
||||
isNullOrUndef(e.(AssignExpr).getRhs())
|
||||
exists (Expr inner |
|
||||
inner = e.stripParens() |
|
||||
// `null` or `undefined`
|
||||
inner instanceof NullLiteral or
|
||||
inner.(VarAccess).getName() = "undefined" or
|
||||
inner instanceof VoidExpr or
|
||||
// recursive case to catch multi-assignments of the form `x = y = null`
|
||||
isNullOrUndef(inner.(AssignExpr).getRhs())
|
||||
)
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -141,4 +141,15 @@ function v() {
|
||||
x = 23;
|
||||
x = 42;
|
||||
return x;
|
||||
}
|
||||
}
|
||||
|
||||
(function(){
|
||||
var x = (void 0);
|
||||
var y = ((void 0));
|
||||
var z1 = z2 = (void 0);
|
||||
x = 42;
|
||||
y = 42;
|
||||
z1 = 42;
|
||||
z2 = 42;
|
||||
return x + y + z1 + z2;
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user