mirror of
https://github.com/denoland/deno.git
synced 2025-09-26 12:19:12 +00:00
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:
parent
0e579ee9dc
commit
6431622a6d
7 changed files with 46 additions and 13 deletions
|
@ -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;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue