fix: mis-detecting imports on JavaScript when there is no checkJs (#4040)

This PR fixes an issue where we recursively analysed imports on plain JS files
in the compiler irrespective of "checkJs" being true. This caused problems
where when analysing the imports of those files, we would mistake some
import like structures (AMD/CommonJS) as dependencies and try to resolve
the "modules" even though the compiler would not actually look at those files.
This commit is contained in:
Kitson Kelly 2020-02-20 14:58:05 +11:00 committed by GitHub
parent 0e579ee9dc
commit 6431622a6d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
7 changed files with 46 additions and 13 deletions

View file

@ -91,7 +91,7 @@ export class SourceFile {
}
/** Process the imports for the file and return them. */
imports(): Array<[string, string]> {
imports(checkJs: boolean): Array<[string, string]> {
if (this.processed) {
throw new Error("SourceFile has already been processed.");
}
@ -102,6 +102,7 @@ export class SourceFile {
log(`Skipping imports for "${this.filename}"`);
return [];
}
const preProcessedFileInfo = ts.preProcessFile(
this.sourceCode,
true,
@ -131,7 +132,13 @@ export class SourceFile {
getMappedModuleName(importedFile, typeDirectives)
]);
}
} else {
} else if (
!(
!checkJs &&
(this.mediaType === MediaType.JavaScript ||
this.mediaType === MediaType.JSX)
)
) {
process(importedFiles);
}
process(referencedFiles);