Skip to content

Commit 146be6b

Browse files
committed
JS: Also resolve re-exports using new resolution
1 parent 8369807 commit 146be6b

File tree

3 files changed

+11
-20
lines changed

3 files changed

+11
-20
lines changed

javascript/ql/lib/semmle/javascript/ES2015Modules.qll

Lines changed: 2 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import javascript
44
private import semmle.javascript.internal.CachedStages
5+
private import semmle.javascript.internal.paths.PathExprResolver
56

67
/**
78
* An ECMAScript 2015 module.
@@ -725,22 +726,7 @@ abstract class ReExportDeclaration extends ExportDeclaration {
725726
cached
726727
Module getReExportedModule() {
727728
Stages::Imports::ref() and
728-
result.getFile() = this.getEnclosingModule().resolve(this.getImportedPath())
729-
or
730-
result = this.resolveFromTypeRoot()
731-
}
732-
733-
/**
734-
* Gets a module in a `node_modules/@types/` folder that matches the imported module name.
735-
*/
736-
private Module resolveFromTypeRoot() {
737-
result.getFile() =
738-
min(TypeRootFolder typeRoot |
739-
|
740-
typeRoot.getModuleFile(this.getImportedPath().getStringValue())
741-
order by
742-
typeRoot.getSearchPriority(this.getFile().getParentContainer())
743-
)
729+
result.getFile() = ImportPathResolver::resolveExpr(this.getImportedPath())
744730
}
745731
}
746732

javascript/ql/lib/semmle/javascript/Modules.qll

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -115,10 +115,6 @@ abstract class Module extends TopLevel {
115115
}
116116
}
117117

118-
private predicate shouldResolveExpr(Expr e) { e = any(Import imprt).getImportedPathExpr() }
119-
120-
private module Resolver = ResolveExpr<shouldResolveExpr/1>;
121-
122118
/**
123119
* An import in a module, which may be an ECMAScript 2015-style
124120
* `import` statement, a CommonJS-style `require` import, or an AMD dependency.

javascript/ql/lib/semmle/javascript/internal/paths/PathExprResolver.qll

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -244,3 +244,12 @@ module ResolveExpr<exprSig/1 shouldResolveExpr> {
244244
query predicate getFileFromFolderImport_ = getFileFromFolderImport/1;
245245
}
246246
}
247+
248+
private predicate isImportPathExpr(Expr e) {
249+
e = any(Import imprt).getImportedPathExpr()
250+
or
251+
e = any(ReExportDeclaration decl).getImportedPath()
252+
}
253+
254+
/** Resolves paths in imports and re-exports. */
255+
module ImportPathResolver = ResolveExpr<isImportPathExpr/1>;

0 commit comments

Comments
 (0)