Skip to content

Commit 7d57d19

Browse files
author
Esben Sparre Andreasen
committed
JS: introduce DataFlow::DependencyModuleImport
1 parent 1cea29d commit 7d57d19

File tree

1 file changed

+10
-0
lines changed
  • javascript/ql/src/semmle/javascript/dataflow

1 file changed

+10
-0
lines changed

javascript/ql/src/semmle/javascript/dataflow/Nodes.qll

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
*/
66

77
import javascript
8+
import semmle.javascript.dependencies.Dependencies
89

910
/** A data flow node corresponding to an expression. */
1011
class ExprNode extends DataFlow::ValueNode {
@@ -487,6 +488,15 @@ module ModuleImportNode {
487488
*/
488489
ModuleImportNode moduleImport(string path) { result.getPath() = path }
489490

491+
/**
492+
* Gets a (default) import of the given dependency `dep`, such as
493+
* `require("lodash")` in a context where a package.json file includes
494+
* `"lodash"` as a dependency.
495+
*/
496+
ModuleImportNode dependencyModuleImport(Dependency dep) {
497+
result = dep.getAUse("import").(Import).getDefaultNode()
498+
}
499+
490500
/**
491501
* Gets a data flow node that either imports `m` from the module with
492502
* the given `path`, or accesses `m` as a member on a default or

0 commit comments

Comments
 (0)