Skip to content

Commit 2d6e3a5

Browse files
committed
support outdir in tsconfig.json
1 parent dfdecf1 commit 2d6e3a5

File tree

2 files changed

+44
-1
lines changed

2 files changed

+44
-1
lines changed

javascript/ql/src/semmle/javascript/NodeJS.qll

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,9 @@ class Require extends CallExpr, Import {
175175

176176
override Module resolveImportedPath() {
177177
moduleInFile(result, load(min(int prio | moduleInFile(_, load(prio)))))
178+
or
179+
not exists(Module mod | moduleInFile(mod, load(_))) and
180+
result = Import.super.resolveImportedPath()
178181
}
179182

180183
/**

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

Lines changed: 41 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,11 @@ abstract class PathString extends string {
145145
n = 0 and result.getContainer() = root and root = getARootFolder()
146146
or
147147
exists(Path base | base = resolveUpTo(n - 1, root) |
148-
exists(string next | next = getComponent(n - 1) |
148+
exists(string next |
149+
next = getComponent(n - 1)
150+
or
151+
next = getOriginalTypeScriptFolder(getComponent(n - 1), base.getContainer())
152+
|
149153
// handle empty components and the special "." folder
150154
(next = "" or next = ".") and
151155
result = base
@@ -174,6 +178,42 @@ abstract class PathString extends string {
174178
Path resolve(Folder root) { result = resolveUpTo(getNumComponent(), root) }
175179
}
176180

181+
/**
182+
* Gets the first folder from `path`.
183+
*/
184+
bindingset[path]
185+
private string getRootFolderFromPath(string path) {
186+
not exists(path.indexOf("/")) and result = path
187+
or
188+
result = path.substring(0, path.indexOf("/", 0, 0))
189+
}
190+
191+
/**
192+
* Gets a folder of TypeScript files that is compiled into JavaScript files in `outdir` relative to a `parent`.
193+
*/
194+
private string getOriginalTypeScriptFolder(string outdir, Folder parent) {
195+
exists(JSONObject tsconfig |
196+
tsconfig.getFile().getBaseName() = "tsconfig.json" and
197+
tsconfig.isTopLevel() and
198+
tsconfig.getFile().getParentContainer() = parent
199+
|
200+
outdir =
201+
tsconfig
202+
.getPropValue("compilerOptions")
203+
.(JSONObject)
204+
.getPropValue("outDir")
205+
.(JSONString)
206+
.getValue() and
207+
result =
208+
getRootFolderFromPath(tsconfig
209+
.getPropValue("include")
210+
.(JSONArray)
211+
.getElementValue(_)
212+
.(JSONString)
213+
.getValue())
214+
)
215+
}
216+
177217
/**
178218
* An expression whose value represents a (relative or absolute) file system path.
179219
*

0 commit comments

Comments
 (0)