mirror of
https://github.com/morluto/rea
synced 2026-10-26 06:16:17 -04:00
fix(javascript): align module lookup and source evidence
Preserve CommonJS literal paths and confined ESM URL semantics, including package main fallback, directory intent, Unicode identity, and present opaque modules. Parse extraction inputs at their AST/source owner, retain skipped HTML and source-map coverage, and distinguish endpoint candidates from proven receiver facts. Version structural fingerprints with computed literal contents and propagate them through worker contracts. Reviewed fixes include #1810, #1840, #2642, #2700, #2702, #2714, #2803, #2960, #2968, #2986, #3035, and #3036. Validation: 158 resolver tests passed; public CLI/MCP module lookup controls, package-main/Unicode workflows, and six builtin workflows passed in the current compiled lane. Worker schema/fingerprint regressions passed. Large public pdf.js completion and real Electron analysis remain unverified.
This commit is contained in:
@@ -410,13 +410,27 @@ const XHR_METHODS = new Set([
|
||||
"TRACE",
|
||||
]);
|
||||
|
||||
/** An absolute HTTP(S)/WebSocket URL, or an absolute or relative path. */
|
||||
const isRequestUrlLiteral = (value: string): boolean =>
|
||||
/** Legacy URL/path shapes that bypass the overloaded lookup exclusions. */
|
||||
const isRequestUrlOrPathLiteral = (value: string): boolean =>
|
||||
/^(?:https?|wss?):\/\//iu.test(value) ||
|
||||
value.startsWith("/") ||
|
||||
value.startsWith("./") ||
|
||||
value.startsWith("../");
|
||||
|
||||
/** Explicit request references, classified after receiver-specific exclusions. */
|
||||
const isRequestUrlReference = (value: string): boolean => {
|
||||
if (
|
||||
isRequestUrlOrPathLiteral(value) ||
|
||||
value.startsWith("?") ||
|
||||
value.startsWith("#")
|
||||
)
|
||||
return true;
|
||||
// WHATWG accepts HTTP/WS scheme forms without authority slashes. Parse
|
||||
// without a base so bare keys stay ambiguous, and keep the source spelling.
|
||||
if (!/^(?:https?|wss?):/iu.test(value)) return false;
|
||||
return URL.parse(value) !== null;
|
||||
};
|
||||
|
||||
/**
|
||||
* Browsing-context and document `open` take a URL or type first and a target
|
||||
* name second. The name is only a spelling, since `parent` or `self` may be a
|
||||
@@ -538,10 +552,20 @@ const isKeyedCollectionReceiver = (callee: t.Node): boolean => {
|
||||
receiver.property,
|
||||
receiver.computed,
|
||||
);
|
||||
return property === "headers" || property === "searchParams";
|
||||
return (
|
||||
property === "headers" ||
|
||||
property === "headersList" ||
|
||||
property === "searchParams"
|
||||
);
|
||||
};
|
||||
|
||||
/** Select the literal URL argument for recognized network callees. */
|
||||
/** A literal endpoint shape or an ambiguous argument of an HTTP-method-named call. */
|
||||
export interface JavaScriptEndpointArgument {
|
||||
readonly kind: "endpoint" | "candidate";
|
||||
readonly value: string;
|
||||
}
|
||||
|
||||
/** Classify one literal without treating a generic method name as network identity. */
|
||||
export const endpointArgument = (
|
||||
name: string,
|
||||
args: readonly (
|
||||
@@ -552,7 +576,11 @@ export const endpointArgument = (
|
||||
)[],
|
||||
callee: t.Node,
|
||||
receiverFact?: JavaScriptOpenReceiverFact,
|
||||
): string | undefined => {
|
||||
): JavaScriptEndpointArgument | undefined => {
|
||||
const literal = (
|
||||
value: string | undefined,
|
||||
): JavaScriptEndpointArgument | undefined =>
|
||||
value === undefined ? undefined : { kind: "endpoint", value };
|
||||
if (receiverFact === "window") return undefined;
|
||||
if (
|
||||
name === "fetch" ||
|
||||
@@ -561,9 +589,18 @@ export const endpointArgument = (
|
||||
name === "EventSource" ||
|
||||
name.endsWith(".EventSource")
|
||||
)
|
||||
return stringValue(args[0]);
|
||||
if (name.endsWith(".open"))
|
||||
return xhrOpenUrl(name, args[0], args[1], receiverFact);
|
||||
return literal(stringValue(args[0]));
|
||||
if (name.endsWith(".open")) {
|
||||
const value = xhrOpenUrl(name, args[0], args[1], receiverFact);
|
||||
if (value === undefined) return undefined;
|
||||
return {
|
||||
kind:
|
||||
stringValue(args[0]) !== undefined || isRequestUrlReference(value)
|
||||
? "endpoint"
|
||||
: "candidate",
|
||||
value,
|
||||
};
|
||||
}
|
||||
const method = ["get", "post", "put", "patch", "delete", "request"].find(
|
||||
(candidate) => name === candidate || name.endsWith(`.${candidate}`),
|
||||
);
|
||||
@@ -572,18 +609,26 @@ export const endpointArgument = (
|
||||
// Only get and delete also belong to the keyed-collection APIs, whose
|
||||
// keys are header, field, and parameter names rather than URLs or paths.
|
||||
// Configuration `get` reads setting keys.
|
||||
return value !== undefined &&
|
||||
if (value === undefined) return undefined;
|
||||
if (
|
||||
(method === "get" || method === "delete") &&
|
||||
!isRequestUrlLiteral(value) &&
|
||||
!isRequestUrlOrPathLiteral(value) &&
|
||||
(isKeyedCollectionReceiver(callee) ||
|
||||
(method === "get" && receiverFact === "configuration"))
|
||||
? undefined
|
||||
: value;
|
||||
(method === "get" &&
|
||||
(receiverFact === "configuration" ||
|
||||
receiverFact === "extension-state")))
|
||||
)
|
||||
return undefined;
|
||||
return {
|
||||
kind: isRequestUrlReference(value) ? "endpoint" : "candidate",
|
||||
value,
|
||||
};
|
||||
}
|
||||
// navigator.sendBeacon(url, data) queues a POST to its first argument.
|
||||
// Beacon URLs are endpoint observations, retaining the upstream API support.
|
||||
if (name === "sendBeacon" || name.endsWith(".sendBeacon"))
|
||||
return stringValue(args[0]);
|
||||
if (name.endsWith("loadURL")) return stringValue(args[0]);
|
||||
return literal(stringValue(args[0]));
|
||||
if (name === "loadURL" || name.endsWith(".loadURL"))
|
||||
return literal(stringValue(args[0]));
|
||||
return undefined;
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user