fix(javascript): require API identity for static application roles

This commit is contained in:
morluto
2026-10-24 02:29:43 +08:00
parent 5c16a85a67
commit 5f13ddd755
15 changed files with 413 additions and 174 deletions
@@ -11,11 +11,11 @@ import {
import { unwrapJavaScriptExpression } from "./javascriptAstValues.js";
import type { JavaScriptStaticPathIntrinsicQuery } from "./javascriptStaticAnalysisHelpers.js";
/** Prove Node's path resolver before applying its argument-selection semantics. */
export const createStaticNodePathResolveQuery = (
/** Prove path and URL intrinsic identity before applying native semantics. */
export const createStaticPathIntrinsicQuery = (
index: JavaScriptBindingIndex,
): JavaScriptStaticPathIntrinsicQuery => {
const facts = new WeakMap<t.Node, boolean>();
const facts = new WeakMap<t.Node, Map<string, boolean>>();
const nativeMethod = (
callee: t.Node,
method: string,
@@ -64,10 +64,24 @@ export const createStaticNodePathResolveQuery = (
nativeMethod(callee.callee, "dirname", ["path", "path/posix"]) &&
sourceFile(callee.arguments[0]);
}
const cached = facts.get(callee);
const kind = fact ?? "resolve";
const cached = facts.get(callee)?.get(kind);
if (cached !== undefined) return cached;
const proven = nativeMethod(callee, "resolve", ["path", "path/posix"]);
facts.set(callee, proven);
const proven =
kind === "source-url"
? t.isNewExpression(callee) &&
callee.arguments.length === 2 &&
isUnmodifiedGlobalReference(callee.callee, index.bindings, "URL") &&
isUnmodifiedImportMetaUrl(callee.arguments[1], index.bindings)
: kind === "file-url-to-path"
? nativeMethod(callee, "fileURLToPath", ["url"])
: nativeMethod(callee, kind, ["path", "path/posix"]);
let entry = facts.get(callee);
if (entry === undefined) {
entry = new Map();
facts.set(callee, entry);
}
entry.set(kind, proven);
return proven;
};
};