Skip to content

Commit 702192c

Browse files
author
Max Schaefer
committed
JavaScript: Make implicit inits of module and exports source nodes.
This is instead of making every access to those variables source nodes, and fixes a regression in `DeadStoreOfProperty`.
1 parent 9840a7d commit 702192c

1 file changed

Lines changed: 9 additions & 10 deletions

File tree

javascript/ql/src/ApiGraphs.qll

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -334,8 +334,7 @@ module API {
334334
exports(m, _, _)
335335
or
336336
exists(NodeModule nm | nm = mod |
337-
exists(nm.getModuleVariable().getAnAccess()) or
338-
exists(nm.getExportsVariable().getAnAccess())
337+
exists(SSA::implicitInit([nm.getModuleVariable(), nm.getExportsVariable()]))
339338
)
340339
)
341340
} or
@@ -529,13 +528,13 @@ module API {
529528
cached
530529
predicate use(Feature nd, DataFlow::SourceNode ref) {
531530
exists(string m, Module mod | nd = MkModule(m) and mod = importableModule(m) |
532-
ref = mod.(NodeModule).getModuleVariable().getAnAccess().flow()
531+
ref = DataFlow::ssaDefinitionNode(SSA::implicitInit(mod.(NodeModule).getModuleVariable()))
533532
or
534533
ref = DataFlow::parameterNode(mod.(AmdModule).getDefine().getModuleParameter())
535534
)
536535
or
537536
exists(string m, Module mod | nd = MkModuleExport(m) and mod = importableModule(m) |
538-
ref = mod.(NodeModule).getExportsVariable().getAnAccess().flow()
537+
ref = DataFlow::ssaDefinitionNode(SSA::implicitInit(mod.(NodeModule).getExportsVariable()))
539538
or
540539
ref = DataFlow::parameterNode(mod.(AmdModule).getDefine().getExportsParameter())
541540
)
@@ -753,14 +752,14 @@ private module Label {
753752
string promised() { result = "promised" }
754753
}
755754

755+
/**
756+
* A CommonJS `module` or `exports` variable, considered as a source node.
757+
*/
756758
private class AdditionalSourceNode extends DataFlow::SourceNode::Range {
757759
AdditionalSourceNode() {
758-
exists(NodeModule m, RValue v |
759-
v = m.getModuleVariable().getAnAccess()
760-
or
761-
v = m.getExportsVariable().getAnAccess()
762-
|
763-
this = v.flow()
760+
exists(NodeModule m, Variable v |
761+
v in [m.getModuleVariable(), m.getExportsVariable()] and
762+
this = DataFlow::ssaDefinitionNode(SSA::implicitInit(v))
764763
)
765764
}
766765
}

0 commit comments

Comments
 (0)