fix(javascript): resolve proven URL constructor aliases

Remove the redundant spelling gate after the shared intrinsic owner proves native constructor and source-base identity. Retain local-constructor and replaced-export uncertainty through public application analysis.
This commit is contained in:
morluto
2026-10-24 10:17:23 +08:00
parent 263a98c6ce
commit 37f24125ad
4 changed files with 49 additions and 21 deletions
@@ -267,12 +267,6 @@ export interface JavaScriptStaticSourceUrlPath {
readonly directory: boolean;
}
/** Read a literal `new URL(relative, import.meta.url)` shape without evaluation. */
export const staticSourceRelativeUrlPath = (
node: t.Node,
): JavaScriptStaticSourceUrlPath | undefined =>
isSourceFileUrl(node) ? sourceRelativeFileUrlPath(node) : undefined;
/** Convert an exact static file URL expression to a POSIX path. */
export const staticFileUrlPath = (
node: t.CallExpression | t.NewExpression,
@@ -282,8 +276,8 @@ export const staticFileUrlPath = (
const rawArgument = argumentNode(node.arguments[0]);
if (rawArgument === undefined) return undefined;
const argument = unwrapJavaScriptExpression(rawArgument).node;
if (isSourceFileUrl(argument) && pathIntrinsics?.(argument, "source-url"))
return sourceRelativeFileUrlPath(argument)?.path;
if (t.isNewExpression(argument) && pathIntrinsics?.(argument, "source-url"))
return staticSourceRelativeUrlPath(argument)?.path;
const value = staticPath(argument, pathIntrinsics);
const rawPath = value?.split(/[?#]/u, 1)[0] ?? "";
if (
@@ -308,9 +302,9 @@ export const staticFileUrlPath = (
}
};
/** Project a known source-relative URL through the actual file URL decoder. */
const sourceRelativeFileUrlPath = (
node: t.CallExpression | t.NewExpression,
/** Decode a source-relative URL after the caller proves constructor and base identity. */
export const staticSourceRelativeUrlPath = (
node: t.NewExpression,
): JavaScriptStaticSourceUrlPath | undefined => {
const value = stringValue(node.arguments[0]);
if (
@@ -350,14 +344,6 @@ const sourceRelativeFileUrlPath = (
}
};
const isSourceFileUrl = (
node: t.Node,
): node is t.CallExpression | t.NewExpression =>
(t.isCallExpression(node) || t.isNewExpression(node)) &&
(calleeName(node.callee) === "URL" ||
calleeName(node.callee).endsWith(".URL")) &&
isFileIdentity(argumentNode(node.arguments[1]));
const staticResolvedPath = (
node: t.CallExpression | t.NewExpression,
pathIntrinsics?: JavaScriptStaticPathIntrinsicQuery,