mirror of
https://github.com/morluto/rea.git
synced 2026-12-04 22:11:12 +00:00
refactor(javascript): share reference resolution projection (#16614)
This commit is contained in:
1 parent
05b8a76122
commit
c33ca2b4f0
1 file changed
+43
-66
@@ -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,
|
||||
};
|
||||
};
|
||||
|
||||
/**
|
||||
|
||||
Reference in new issue
Block a user