Skip to content

Commit c34b14c

Browse files
committed
JS: Implement getTypingsFile() in PackageJsonEx
1 parent 1bf053e commit c34b14c

File tree

2 files changed

+16
-13
lines changed

2 files changed

+16
-13
lines changed

javascript/ql/lib/semmle/javascript/NPM.qll

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -245,19 +245,7 @@ class PackageJson extends JsonObject {
245245
* Gets the file containing the typings of this package, which can either be from the `types` or
246246
* `typings` field, or derived from the `main` or `module` fields.
247247
*/
248-
File getTypingsFile() {
249-
result =
250-
TypingsModulePathString::of(this).resolve(this.getFile().getParentContainer()).getContainer()
251-
or
252-
not exists(TypingsModulePathString::of(this)) and
253-
exists(File mainFile |
254-
mainFile = this.getMainModule().getFile() and
255-
result =
256-
mainFile
257-
.getParentContainer()
258-
.getFile(mainFile.getStem().regexpReplaceAll("\\.d$", "") + ".d.ts")
259-
)
260-
}
248+
File getTypingsFile() { none() } // implemented in PackageJsonEx
261249

262250
/**
263251
* Gets the module containing the typings of this package, which can either be from the `types` or

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

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,19 @@ class PackageJsonEx extends PackageJson {
7070
Container getAFileInFilesArray() {
7171
result = Resolver::resolve(this.getFolder(), this.getAPathInFilesArray())
7272
}
73+
74+
override File getTypingsFile() {
75+
result = Resolver::resolve(this.getFolder(), this.getTypings())
76+
or
77+
not exists(this.getTypings()) and
78+
exists(File mainFile |
79+
mainFile = this.getMainFileOrBestGuess() and
80+
result =
81+
mainFile
82+
.getParentContainer()
83+
.getFile(mainFile.getStem().regexpReplaceAll("\\.d$", "") + ".d.ts")
84+
)
85+
}
7386
}
7487

7588
private module ResolverConfig implements Folder::ResolveSig {
@@ -83,6 +96,8 @@ private module ResolverConfig implements Folder::ResolveSig {
8396
path = pkg.getMainPath()
8497
or
8598
path = pkg.getAPathInFilesArray()
99+
or
100+
path = pkg.getTypings()
86101
)
87102
}
88103

0 commit comments

Comments
 (0)