From 6431622a6debc0443f9269fe0157571ec54701c0 Mon Sep 17 00:00:00 2001 From: Kitson Kelly Date: Thu, 20 Feb 2020 14:58:05 +1100 Subject: 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. --- cli/js/compiler_sourcefile.ts | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) (limited to 'cli/js/compiler_sourcefile.ts') diff --git a/cli/js/compiler_sourcefile.ts b/cli/js/compiler_sourcefile.ts index faa096ba8..23fefbf41 100644 --- a/cli/js/compiler_sourcefile.ts +++ b/cli/js/compiler_sourcefile.ts @@ -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); -- cgit v1.2.3