diff options
author | Kitson Kelly <me@kitsonkelly.com> | 2020-02-20 14:58:05 +1100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-02-19 22:58:05 -0500 |
commit | 6431622a6debc0443f9269fe0157571ec54701c0 (patch) | |
tree | 8657fe0eaeb492283f369c0813d46880683e5efb /cli/js/compiler_imports.ts | |
parent | 0e579ee9dce917c1b783cea5506315f78b1e0a00 (diff) |
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.
Diffstat (limited to 'cli/js/compiler_imports.ts')
-rw-r--r-- | cli/js/compiler_imports.ts | 19 |
1 files changed, 15 insertions, 4 deletions
diff --git a/cli/js/compiler_imports.ts b/cli/js/compiler_imports.ts index 042c0a1ae..09b2d4ba1 100644 --- a/cli/js/compiler_imports.ts +++ b/cli/js/compiler_imports.ts @@ -120,7 +120,8 @@ function getMediaType(filename: string): MediaType { export function processLocalImports( sources: Record<string, string>, specifiers: Array<[string, string]>, - referrer?: string + referrer?: string, + checkJs = false ): string[] { if (!specifiers.length) { return []; @@ -143,7 +144,12 @@ export function processLocalImports( }); sourceFile.cache(specifiers[i][0], referrer); if (!sourceFile.processed) { - processLocalImports(sources, sourceFile.imports(), sourceFile.url); + processLocalImports( + sources, + sourceFile.imports(checkJs), + sourceFile.url, + checkJs + ); } } return moduleNames; @@ -157,7 +163,8 @@ export function processLocalImports( * that should be actually resolved. */ export async function processImports( specifiers: Array<[string, string]>, - referrer?: string + referrer?: string, + checkJs = false ): Promise<string[]> { if (!specifiers.length) { return []; @@ -172,7 +179,11 @@ export async function processImports( SourceFile.get(sourceFileJson.url) || new SourceFile(sourceFileJson); sourceFile.cache(specifiers[i][0], referrer); if (!sourceFile.processed) { - await processImports(sourceFile.imports(), sourceFile.url); + await processImports( + sourceFile.imports(checkJs), + sourceFile.url, + checkJs + ); } } return resolvedSources; |