Files
reverse-engineering-anything/src/domain/webBundleAnalyzerAst.ts
T
SII-YDDandgensokyo-dev d4c511ae6e fix(javascript): honor effective symbolic descriptor values (#7222)
Resolve ordered descriptor values at the shared JavaScript fact owner and preserve uncertain intrinsic writes instead of stale exports. Normalize ordinary method values and reuse canonical primitive, prototype, ambient identity and ordering facts across consumers.

384 selected tests, format/static/docs checks, all final CI jobs and reviews pass. Actual Node controls cover 35 bundles; one possibly repeated factory explicitly stays unknown. Shipped Obsidian selected-source complete Evidence matches base/fixed CLI and MCP, with coverage and resource measurements in the PR.

Co-authored-by: gensokyo-dev <342580529+gensokyo-dev@users.noreply.github.com>
2026-10-27 03:08:00 +08:00

65 lines
1.9 KiB
TypeScript

import * as t from "@babel/types";
import { sanitizeBrowserUrl } from "./browserObservation.js";
import { hasScheme } from "./artifactPathSyntax.js";
import {
isNullishJavaScriptSyntax,
readExactJavaScriptLiteral,
staticObjectProperty,
type ObjectDataPropertyValue,
} from "./javascript/javascriptAstValues.js";
/** Read a statically known own property value from an object expression. */
export const objectValue = (
object: t.ObjectExpression,
name: string,
): ObjectDataPropertyValue | undefined => {
const result = staticObjectProperty(object, name, isNullishJavaScriptSyntax);
return result.status === "explicit" ? result.value : undefined;
};
export const objectString = (
object: t.ObjectExpression,
name: string,
): string | undefined => {
const value = objectValue(object, name);
if (value === undefined) return undefined;
const literal = readExactJavaScriptLiteral(value);
return literal.found && typeof literal.value === "string"
? literal.value
: undefined;
};
/** Whether module syntax supplies a URL location without a package/import-map resolver. */
export const isUrlLikeModuleSpecifier = (specifier: string): boolean =>
specifier.startsWith("/") ||
specifier.startsWith("./") ||
specifier.startsWith("../") ||
hasScheme(specifier);
export const resolveSpecifier = (
specifier: string,
base: string,
): string | null => {
try {
const resolved = new URL(specifier, base);
if (resolved.protocol !== "http:" && resolved.protocol !== "https:")
return null;
return sanitizeBrowserUrl(resolved.href).url;
} catch (cause: unknown) {
// Unresolvable specifiers are represented by the null return.
void cause;
return null;
}
};
export const location = (scriptKey: string, node: t.Node) => ({
script_key: scriptKey,
...locationFields(node),
});
export const locationFields = (node: t.Node) => ({
line: node.loc?.start.line ?? null,
column: node.loc?.start.column ?? null,
});