Skip to content

Commit 3846f53

Browse files
committed
JS: Factor out overridden part of PathExpr.getSearchRoot
1 parent 5f51087 commit 3846f53

File tree

2 files changed

+13
-3
lines changed

2 files changed

+13
-3
lines changed

javascript/ql/src/semmle/javascript/NodeModuleResolutionImpl.qll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ class MainModulePath extends PathExpr, @json_string {
112112

113113
override string getValue() { result = this.(JSONString).getValue() }
114114

115-
override Folder getSearchRoot(int priority) {
115+
override Folder getAdditionalSearchRoot(int priority) {
116116
priority = 0 and
117117
result = pkg.getFile().getParentContainer()
118118
}

javascript/ql/src/semmle/javascript/Paths.qll

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -194,8 +194,18 @@ abstract class PathExpr extends Locatable {
194194
Folder getSearchRoot(int priority) {
195195
// We default to the enclosing module's search root, though this may be overridden.
196196
getEnclosingModule().searchRoot(this, result, priority)
197+
or
198+
result = getAdditionalSearchRoot(priority)
197199
}
198200

201+
/**
202+
* INTERNAL. Use `getSearchRoot` instead.
203+
*
204+
* Can be overridden by subclasses of `PathExpr` to provide additional search roots
205+
* without overriding `getSearchRoot`.
206+
*/
207+
Folder getAdditionalSearchRoot(int priority) { none() }
208+
199209
/** Gets the `i`th component of this path. */
200210
string getComponent(int i) { result = getValue().(PathString).getComponent(i) }
201211

@@ -276,8 +286,8 @@ private class ConcatPath extends PathExpr {
276286
)
277287
}
278288

279-
override Folder getSearchRoot(int priority) {
280-
result = this.(AddExpr).getAnOperand().(PathExpr).getSearchRoot(priority)
289+
override Folder getAdditionalSearchRoot(int priority) {
290+
result = this.(AddExpr).getAnOperand().(PathExpr).getAdditionalSearchRoot(priority)
281291
}
282292
}
283293

0 commit comments

Comments
 (0)