support outdir in tsconfig.json

This commit is contained in:
Erik Krogh Kristensen
2020-05-13 21:00:02 +02:00
parent dfdecf1450
commit 2d6e3a5784
2 changed files with 44 additions and 1 deletions

View File

@@ -175,6 +175,9 @@ class Require extends CallExpr, Import {
override Module resolveImportedPath() {
moduleInFile(result, load(min(int prio | moduleInFile(_, load(prio)))))
or
not exists(Module mod | moduleInFile(mod, load(_))) and
result = Import.super.resolveImportedPath()
}
/**

View File

@@ -145,7 +145,11 @@ abstract class PathString extends string {
n = 0 and result.getContainer() = root and root = getARootFolder()
or
exists(Path base | base = resolveUpTo(n - 1, root) |
exists(string next | next = getComponent(n - 1) |
exists(string next |
next = getComponent(n - 1)
or
next = getOriginalTypeScriptFolder(getComponent(n - 1), base.getContainer())
|
// handle empty components and the special "." folder
(next = "" or next = ".") and
result = base
@@ -174,6 +178,42 @@ abstract class PathString extends string {
Path resolve(Folder root) { result = resolveUpTo(getNumComponent(), root) }
}
/**
* Gets the first folder from `path`.
*/
bindingset[path]
private string getRootFolderFromPath(string path) {
not exists(path.indexOf("/")) and result = path
or
result = path.substring(0, path.indexOf("/", 0, 0))
}
/**
* Gets a folder of TypeScript files that is compiled into JavaScript files in `outdir` relative to a `parent`.
*/
private string getOriginalTypeScriptFolder(string outdir, Folder parent) {
exists(JSONObject tsconfig |
tsconfig.getFile().getBaseName() = "tsconfig.json" and
tsconfig.isTopLevel() and
tsconfig.getFile().getParentContainer() = parent
|
outdir =
tsconfig
.getPropValue("compilerOptions")
.(JSONObject)
.getPropValue("outDir")
.(JSONString)
.getValue() and
result =
getRootFolderFromPath(tsconfig
.getPropValue("include")
.(JSONArray)
.getElementValue(_)
.(JSONString)
.getValue())
)
}
/**
* An expression whose value represents a (relative or absolute) file system path.
*