Skip to content

Commit 82b35a1

Browse files
committed
JS: Handle .js import of .ts file
1 parent 8f39989 commit 82b35a1

File tree

2 files changed

+8
-1
lines changed

2 files changed

+8
-1
lines changed

javascript/ql/src/semmle/javascript/Modules.qll

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,9 +83,13 @@ abstract class Module extends TopLevel {
8383
result = c.(Folder).getJavaScriptFile("index")
8484
)
8585
or
86-
// handle the case where the import path is missing an extension
86+
// handle the case where the import path is missing the extension
8787
exists(Folder f | f = path.resolveUpTo(path.getNumComponent() - 1) |
8888
result = f.getJavaScriptFile(path.getBaseName())
89+
or
90+
// If a js file was not found look for a file that compiles to js
91+
not exists(f.getJavaScriptFile(path.getBaseName())) and
92+
result = f.getJavaScriptFile(path.getStem())
8993
)
9094
)
9195
}

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -205,6 +205,9 @@ abstract class PathExpr extends PathExprBase {
205205
/** Gets the base name of the folder or file this path refers to. */
206206
string getBaseName() { result = getValue().(PathString).getBaseName() }
207207

208+
/** Gets the stem, that is, base name without extension, of the folder or file this path refers to. */
209+
string getStem() { result = getValue().(PathString).getStem() }
210+
208211
/**
209212
* Gets the file or folder that the first `n` components of this path refer to
210213
* when resolved relative to the root folder of the given `priority`.

0 commit comments

Comments
 (0)