diff --git a/src/application/javascript/JavaScriptArtifactGraphFindings.ts b/src/application/javascript/JavaScriptArtifactGraphFindings.ts index a17d821dc64..2150dc50b3f 100644 --- a/src/application/javascript/JavaScriptArtifactGraphFindings.ts +++ b/src/application/javascript/JavaScriptArtifactGraphFindings.ts @@ -756,35 +756,25 @@ const resolveReference = ( const resolution = viteDependency !== undefined ? resolveViteOutputDependency(context, sourcePath, viteDependency) - : isWorker - ? resolveArtifactPathByContext({ - declaredPath: specifier, - sourcePath, - context: "url-reference", - files: context.filesByPath, - jsonDocuments: context.analysis.jsonDocuments, - directoryPaths: context.directoryPaths, - unanalyzedFiles: context.unanalyzedFiles, - }) - : resolveArtifactPathByContext({ - declaredPath: specifier, - sourcePath: resolutionSourcePath, - context: "module-specifier", - files: context.filesByPath, - jsonDocuments: context.analysis.jsonDocuments, - directoryPaths: context.directoryPaths, - unanalyzedFiles: context.unanalyzedFiles, - ...("require" === reference.kind || - "static-import" === reference.kind || - "dynamic-import" === reference.kind - ? { - moduleKind: moduleResolutionModeForJavaScriptReference( - resolutionSourcePath, - reference.kind, - ), - } - : {}), - }); + : resolveArtifactPathByContext({ + declaredPath: specifier, + sourcePath: resolutionSourcePath, + context: isWorker ? "url-reference" : "module-specifier", + files: context.filesByPath, + jsonDocuments: context.analysis.jsonDocuments, + directoryPaths: context.directoryPaths, + unanalyzedFiles: context.unanalyzedFiles, + ...("require" === reference.kind || + "static-import" === reference.kind || + "dynamic-import" === reference.kind + ? { + moduleKind: moduleResolutionModeForJavaScriptReference( + resolutionSourcePath, + reference.kind, + ), + } + : {}), + }); const path = resolution.resolved_path; const targetPath = path ?? resolution.candidate_path; const targetKind = @@ -804,43 +794,30 @@ const resolveReference = ( resolution.resolution_status === "unavailable" || (path !== null && !context.applicationModuleReferencesRetained.has(path))); - if (path === null) { - const source = context.filesByPath.get(sourcePath); - return source === undefined - ? null - : { - path: null, - file: null, - node: isWorker - ? null - : unresolvedReferenceNode( - context, - source, - reference, - coverage, - resolution, - ), - limitations: resolution.limitations, - ...(targetImportsUnexamined - ? { targetImportsUnexamined: true as const } - : {}), - resolution, - }; - } - const file = context.filesByPath.get(path); - const node = context.fileNodes.get(path); - return file === undefined || node === undefined - ? null - : { - path, - file, - node, - limitations: resolution.limitations, - ...(targetImportsUnexamined - ? { targetImportsUnexamined: true as const } - : {}), - resolution, - }; + const file = context.filesByPath.get(path ?? sourcePath); + const node = + path !== null + ? context.fileNodes.get(path) + : file === undefined || isWorker + ? null + : unresolvedReferenceNode( + context, + file, + reference, + coverage, + resolution, + ); + if (file === undefined || node === undefined) return null; + return { + path, + file: path === null ? null : file, + node, + limitations: resolution.limitations, + ...(targetImportsUnexamined + ? { targetImportsUnexamined: true as const } + : {}), + resolution, + }; }; /**