Skip to content

Commit 9868d61

Browse files
committed
JS: Add toDataFlowNode() and use more consistently
1 parent ab5acbf commit 9868d61

File tree

3 files changed

+14
-14
lines changed

3 files changed

+14
-14
lines changed

javascript/ql/lib/semmle/javascript/dataflow/internal/CallGraphs.qll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ module CallGraph {
1414
Function getAFunctionValue(AnalyzedNode node) {
1515
result = node.getAValue().(AbstractCallable).getFunction()
1616
or
17-
node = DataFlow::valueNode(NameResolution::trackFunctionValue(result))
17+
node = NameResolution::trackFunctionValue(result).toDataFlowNode().(DataFlow::SourceNode)
1818
}
1919

2020
/** Holds if the type inferred for `node` is indefinite due to global flow. */

javascript/ql/lib/semmle/javascript/dataflow/internal/FlowSteps.qll

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -336,27 +336,17 @@ private module CachedSteps {
336336
// TODO: Ensure name resolution has good enough support for NodeJS and AMD
337337
exists(NameResolution::Node node1, NameResolution::Node node2 |
338338
NameResolution::ValueFlow::resolvedReadStep(node1, node2) and
339-
pred = DataFlow::valueNode(node1) and
340-
succ = getNodeFromNameResolutionNode(node2)
339+
pred = node1.toDataFlowNode() and
340+
succ = node2.toDataFlowNode()
341341
)
342342
or
343343
exists(Import imprt, Module mod |
344344
imprt.getImportedModule() = mod and
345-
pred = DataFlow::valueNode(NameResolution::getModuleBulkExport(mod)) and
345+
pred = NameResolution::getModuleBulkExport(mod).toDataFlowNode() and
346346
succ = imprt.getImportedModuleNodeStrict()
347347
)
348348
}
349349

350-
pragma[inline]
351-
private DataFlow::Node getNodeFromNameResolutionNode(NameResolution::Node node) {
352-
result = DataFlow::valueNode(node)
353-
or
354-
exists(ImportSpecifier spec |
355-
node = spec.getLocal() and
356-
result = DataFlow::valueNode(spec)
357-
)
358-
}
359-
360350
/**
361351
* Gets a node whose value is assigned to `gv` in `f`.
362352
*/

javascript/ql/lib/semmle/javascript/internal/NameResolution.qll

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,16 @@ module NameResolution {
3434
or
3535
result = this.(JSDocTypeExpr).getLocation()
3636
}
37+
38+
DataFlow::Node toDataFlowNode() {
39+
result = DataFlow::valueNode(this)
40+
or
41+
// TODO: refactor graph to avoid the need for this
42+
exists(ImportSpecifier spec |
43+
this = spec.getLocal() and
44+
result = DataFlow::valueNode(spec)
45+
)
46+
}
3747
}
3848

3949
private signature predicate nodeSig(Node node);

0 commit comments

Comments
 (0)