mirror of
https://github.com/github/codeql.git
synced 2026-04-29 18:55:14 +02:00
JS: Treat d.ts as a single extension in Folder.getJavaScriptFile
This commit is contained in:
@@ -175,6 +175,15 @@ class Folder extends Container, @folder {
|
||||
result.getExtension() = extension
|
||||
}
|
||||
|
||||
/** Like `getFile` except `d.ts` is treated as a single extension. */
|
||||
private File getFileLongExtension(string stem, string extension) {
|
||||
not (stem.matches("%.d") and extension = "ts") and
|
||||
result = this.getFile(stem, extension)
|
||||
or
|
||||
extension = "d.ts" and
|
||||
result = this.getFile(stem + ".d", "ts")
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the file in this folder that has the given `stem` and any of the supported JavaScript extensions.
|
||||
*
|
||||
@@ -188,7 +197,11 @@ class Folder extends Container, @folder {
|
||||
*/
|
||||
File getJavaScriptFile(string stem) {
|
||||
result =
|
||||
min(int p, string ext | p = getFileExtensionPriority(ext) | this.getFile(stem, ext) order by p)
|
||||
min(int p, string ext |
|
||||
p = getFileExtensionPriority(ext)
|
||||
|
|
||||
this.getFileLongExtension(stem, ext) order by p
|
||||
)
|
||||
}
|
||||
|
||||
/** Gets a subfolder contained in this folder. */
|
||||
|
||||
@@ -33,6 +33,8 @@ int getFileExtensionPriority(string ext) {
|
||||
ext = "json" and result = 8
|
||||
or
|
||||
ext = "node" and result = 9
|
||||
or
|
||||
ext = "d.ts" and result = 10
|
||||
}
|
||||
|
||||
int prioritiesPerCandidate() { result = 3 * (numberOfExtensions() + 1) }
|
||||
|
||||
@@ -1 +1,2 @@
|
||||
| main.ts:1:1:1:52 | import ... -file"; | ./only-declaration-file | only-declaration-file.d.ts:3:1:4:0 | <toplevel> |
|
||||
| main.ts:2:1:2:48 | import ... -file"; | ./has-javascript-file | has-javascript-file.js:1:1:2:0 | <toplevel> |
|
||||
|
||||
Reference in New Issue
Block a user