Skip to content

Commit 8533973

Browse files
committed
JS: Do not treat AMD pseudo-dependencies as file paths
1 parent 052a8e7 commit 8533973

File tree

2 files changed

+12
-3
lines changed

2 files changed

+12
-3
lines changed

javascript/ql/lib/semmle/javascript/AMD.qll

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,13 @@ class AmdModuleDefinition extends CallExpr instanceof AmdModuleDefinition::Range
6161
}
6262

6363
/** Gets the `i`th dependency of this module definition. */
64-
PathExpr getDependency(int i) { result = this.getDependencies().getElement(i) }
64+
PathExpr getDependency(int i) {
65+
exists(Expr expr |
66+
expr = this.getDependencies().getElement(i) and
67+
not isPseudoDependency(expr.getStringValue()) and
68+
result = expr
69+
)
70+
}
6571

6672
/** Gets a dependency of this module definition. */
6773
PathExpr getADependency() {
@@ -203,11 +209,15 @@ class AmdModuleDefinition extends CallExpr instanceof AmdModuleDefinition::Range
203209
}
204210
}
205211

212+
private predicate isPseudoDependency(string s) { s = ["exports", "require", "module"] }
213+
206214
/** An AMD dependency, considered as a path expression. */
207215
private class AmdDependencyPath extends PathExprCandidate {
208216
AmdDependencyPath() {
209217
exists(AmdModuleDefinition amd |
210-
this = amd.getDependencies().getAnElement() or
218+
this = amd.getDependencies().getAnElement() and
219+
not isPseudoDependency(this.getStringValue())
220+
or
211221
this = amd.getARequireCall().getAnArgument()
212222
)
213223
}

javascript/ql/test/library-tests/AMD/tests.expected

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,6 @@ amdModuleDefinition
6161
| umd.js:4:9:4:43 | define( ... actory) | umd.js:1:18:1:24 | factory |
6262
| umd.js:4:9:4:43 | define( ... actory) | umd.js:9:9:14:1 | functio ... };\\n} |
6363
amdModuleDependencies
64-
| tst2.js:1:1:3:2 | define( ... 42;\\n}) | tst2.js:1:9:1:17 | 'exports' |
6564
| tst3.js:1:1:3:2 | define( ... 42;\\n}) | tst3.js:2:21:2:25 | './a' |
6665
| tst4.js:1:1:11:2 | define( ... };\\n}) | tst4.js:2:9:2:14 | 'a.js' |
6766
| tst4.js:1:1:11:2 | define( ... };\\n}) | tst4.js:3:9:3:13 | 'foo' |

0 commit comments

Comments
 (0)