JS: Add test for missing getALocalSource flow for rest pattern

This commit is contained in:
Asger F
2025-04-11 08:26:04 +02:00
parent 14c5495b4c
commit 7703b1fab5
4 changed files with 48 additions and 0 deletions

View File

@@ -0,0 +1,15 @@
function t1() {
const { ...rest } = source('t1.1');
rest; // $ MISSING: getALocalSource=rest
}
function t2() {
const [ ...rest ] = source('t2.1');
rest; // $ MISSING: getALocalSource=rest
}
function t3() {
const { p1, ...rest } = source('t3.1');
p1; // $ getALocalSource=p1
rest; // $ MISSING: getALocalSource=rest
}

View File

@@ -0,0 +1 @@
| rest-pattern.js:13:5:13:6 | p1 | p1 |

View File

@@ -0,0 +1,30 @@
import javascript
string nodeName(DataFlow::SourceNode node) {
result = node.getAstNode().(VarRef).getName()
or
result = node.getAstNode().(PropertyPattern).getName()
or
result = node.getAstNode().(PropAccess).getPropertyName()
or
exists(DataFlow::InvokeNode invoke |
node = invoke and
invoke.getCalleeName() = "source" and
result = invoke.getArgument(0).getStringValue()
)
}
bindingset[node1, node2]
pragma[inline_late]
predicate sameLine(DataFlow::Node node1, DataFlow::Node node2) {
node1.getLocation().getFile() = node2.getLocation().getFile() and
node1.getLocation().getStartLine() = node2.getLocation().getStartLine()
}
query predicate getALocalSource(DataFlow::Node node, string name) {
exists(DataFlow::SourceNode sn |
sn = node.getALocalSource() and
name = nodeName(sn) and
not sameLine(node, sn)
)
}

View File

@@ -0,0 +1,2 @@
query: test.ql
postprocess: utils/test/InlineExpectationsTestQuery.ql