Skip to content

Commit 7703b1f

Browse files
committed
JS: Add test for missing getALocalSource flow for rest pattern
1 parent 14c5495 commit 7703b1f

File tree

4 files changed

+48
-0
lines changed

4 files changed

+48
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
function t1() {
2+
const { ...rest } = source('t1.1');
3+
rest; // $ MISSING: getALocalSource=rest
4+
}
5+
6+
function t2() {
7+
const [ ...rest ] = source('t2.1');
8+
rest; // $ MISSING: getALocalSource=rest
9+
}
10+
11+
function t3() {
12+
const { p1, ...rest } = source('t3.1');
13+
p1; // $ getALocalSource=p1
14+
rest; // $ MISSING: getALocalSource=rest
15+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
| rest-pattern.js:13:5:13:6 | p1 | p1 |
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
import javascript
2+
3+
string nodeName(DataFlow::SourceNode node) {
4+
result = node.getAstNode().(VarRef).getName()
5+
or
6+
result = node.getAstNode().(PropertyPattern).getName()
7+
or
8+
result = node.getAstNode().(PropAccess).getPropertyName()
9+
or
10+
exists(DataFlow::InvokeNode invoke |
11+
node = invoke and
12+
invoke.getCalleeName() = "source" and
13+
result = invoke.getArgument(0).getStringValue()
14+
)
15+
}
16+
17+
bindingset[node1, node2]
18+
pragma[inline_late]
19+
predicate sameLine(DataFlow::Node node1, DataFlow::Node node2) {
20+
node1.getLocation().getFile() = node2.getLocation().getFile() and
21+
node1.getLocation().getStartLine() = node2.getLocation().getStartLine()
22+
}
23+
24+
query predicate getALocalSource(DataFlow::Node node, string name) {
25+
exists(DataFlow::SourceNode sn |
26+
sn = node.getALocalSource() and
27+
name = nodeName(sn) and
28+
not sameLine(node, sn)
29+
)
30+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
query: test.ql
2+
postprocess: utils/test/InlineExpectationsTestQuery.ql

0 commit comments

Comments
 (0)