Skip to content

Commit 34b33ca

Browse files
author
Max Schaefer
committed
JavaScript: Recognise rest patterns as lvalues.
1 parent 394d7b7 commit 34b33ca

File tree

3 files changed

+9
-1
lines changed

3 files changed

+9
-1
lines changed

javascript/ql/src/semmle/javascript/DefUse.qll

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,8 @@ private predicate lvalAux(Expr l, ControlFlowNode def) {
9898
exists (ArrayPattern ap | lvalAux(ap, def) | l = ap.getAnElement().stripParens())
9999
or
100100
exists (ObjectPattern op | lvalAux(op, def) |
101-
l = op.getAPropertyPattern().getValuePattern().stripParens()
101+
l = op.getAPropertyPattern().getValuePattern().stripParens() or
102+
l = op.getRest().stripParens()
102103
)
103104
}
104105

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,5 @@
44
| test.js:54:10:54:10 | z | Variable z is used like a local variable, but is missing a declaration. |
55
| test.js:60:6:60:6 | y | Variable y is used like a local variable, but is missing a declaration. |
66
| test.js:66:2:66:2 | z | Variable z is used like a local variable, but is missing a declaration. |
7+
| tst3.js:7:10:7:10 | x | Variable x is used like a local variable, but is missing a declaration. |
8+
| tst3.js:7:16:7:19 | rest | Variable rest is used like a local variable, but is missing a declaration. |

javascript/ql/test/query-tests/Declarations/MissingVarDecl/tst3.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,8 @@ function sc_alert(i) {
22
for(;i;) ;
33
foo;
44
}
5+
6+
function f(o) {
7+
for({x, ...rest} of o)
8+
console.log(x in rest);
9+
}

0 commit comments

Comments
 (0)