JS: Do not treat AMD pseudo-dependencies as file paths

This commit is contained in:
Asger F
2024-02-28 13:51:28 +01:00
parent 052a8e7f81
commit 853397361f
2 changed files with 12 additions and 3 deletions

View File

@@ -61,7 +61,13 @@ class AmdModuleDefinition extends CallExpr instanceof AmdModuleDefinition::Range
}
/** Gets the `i`th dependency of this module definition. */
PathExpr getDependency(int i) { result = this.getDependencies().getElement(i) }
PathExpr getDependency(int i) {
exists(Expr expr |
expr = this.getDependencies().getElement(i) and
not isPseudoDependency(expr.getStringValue()) and
result = expr
)
}
/** Gets a dependency of this module definition. */
PathExpr getADependency() {
@@ -203,11 +209,15 @@ class AmdModuleDefinition extends CallExpr instanceof AmdModuleDefinition::Range
}
}
private predicate isPseudoDependency(string s) { s = ["exports", "require", "module"] }
/** An AMD dependency, considered as a path expression. */
private class AmdDependencyPath extends PathExprCandidate {
AmdDependencyPath() {
exists(AmdModuleDefinition amd |
this = amd.getDependencies().getAnElement() or
this = amd.getDependencies().getAnElement() and
not isPseudoDependency(this.getStringValue())
or
this = amd.getARequireCall().getAnArgument()
)
}

View File

@@ -61,7 +61,6 @@ amdModuleDefinition
| umd.js:4:9:4:43 | define( ... actory) | umd.js:1:18:1:24 | factory |
| umd.js:4:9:4:43 | define( ... actory) | umd.js:9:9:14:1 | functio ... };\\n} |
amdModuleDependencies
| tst2.js:1:1:3:2 | define( ... 42;\\n}) | tst2.js:1:9:1:17 | 'exports' |
| tst3.js:1:1:3:2 | define( ... 42;\\n}) | tst3.js:2:21:2:25 | './a' |
| tst4.js:1:1:11:2 | define( ... };\\n}) | tst4.js:2:9:2:14 | 'a.js' |
| tst4.js:1:1:11:2 | define( ... };\\n}) | tst4.js:3:9:3:13 | 'foo' |