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

@ -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;