Skip to content

Commit cc3f9bf

Browse files
committed
fix performance issue by inlining a simpler version of getASourceProp
1 parent 0584a6a commit cc3f9bf

File tree

1 file changed

+16
-1
lines changed

1 file changed

+16
-1
lines changed

javascript/ql/lib/semmle/javascript/NodeJS.qll

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ class NodeModule extends Module {
9797
// }
9898
exists(DynamicPropertyAccess::EnumeratedPropName read, Import imp, DataFlow::PropWrite write |
9999
read.getSourceObject().getALocalSource().asExpr() = imp and
100-
read.getASourceProp() = write.getRhs() and
100+
getASourceProp(read) = write.getRhs() and
101101
write.getBase() = this.getAModuleExportsNode() and
102102
write.getPropertyNameExpr().flow().getImmediatePredecessor*() = read and
103103
result = imp.getImportedModule().getAnExportedValue(name)
@@ -163,6 +163,21 @@ class NodeModule extends Module {
163163
}
164164
}
165165

166+
// An copy of `DynamicPropertyAccess::EnumeratedPropName::getASourceProp` that doesn't use the callgraph.
167+
// This avoids making the module-imports recursive with the callgraph.
168+
private DataFlow::SourceNode getASourceProp(DynamicPropertyAccess::EnumeratedPropName prop) {
169+
exists(DataFlow::Node base, DataFlow::Node key |
170+
exists(DynamicPropertyAccess::DynamicPropRead read |
171+
not read.hasDominatingAssignment() and
172+
base = read.getBase() and
173+
key = read.getPropertyNameNode() and
174+
result = read
175+
) and
176+
prop.getASourceObjectRef().flowsTo(base) and
177+
key.getImmediatePredecessor*() = prop
178+
)
179+
}
180+
166181
/**
167182
* Gets an expression that syntactically could be a alias for `module.exports`.
168183
* This predicate exists to reduce the size of `getAModuleExportsNode`,

0 commit comments

Comments
 (0)