mirror of
https://github.com/morluto/rea
synced 2026-10-26 06:16:17 -04:00
refactor: use canonical implementations and types directly
Remove forwarding wrappers and shadow aliases, migrate callers and verification scripts to their owners, and share one exhaustive semantic resource-bound projection.
This commit is contained in:
@@ -15,7 +15,7 @@ import {
|
||||
readExactJavaScriptLiteral,
|
||||
semanticStaticPropertyName,
|
||||
} from "./javascriptAstValues.js";
|
||||
import { compareCodePoints } from "../canonicalOrdering.js";
|
||||
import { compareUnicodeCodePoints } from "../unicodeCodePointOrder.js";
|
||||
|
||||
/** Explicit result for source text that Babel cannot parse. */
|
||||
export const failedJavaScriptStaticAnalysis = (): JavaScriptStaticAnalysis => ({
|
||||
@@ -156,17 +156,13 @@ export const staticArrayValues = (
|
||||
const value = argumentValue(element);
|
||||
return value === undefined ? [] : [value];
|
||||
});
|
||||
const values = [...new Set(staticValues)].sort(compareCodePoints);
|
||||
const values = [...new Set(staticValues)].sort(compareUnicodeCodePoints);
|
||||
return {
|
||||
values,
|
||||
unknown: array.elements.length - staticValues.length,
|
||||
};
|
||||
};
|
||||
|
||||
/** Resolve a path composed only from inert literal syntax. */
|
||||
export const staticPath = (node: t.Node): string | undefined =>
|
||||
staticPathAt(node);
|
||||
|
||||
/** Classify whether inert path syntax is a module specifier or file expression. */
|
||||
export const staticPathResolutionContext = (
|
||||
node: t.Node,
|
||||
@@ -175,13 +171,14 @@ export const staticPathResolutionContext = (
|
||||
? "filesystem-expression"
|
||||
: "module-specifier";
|
||||
|
||||
const staticPathAt = (node: t.Node): string | undefined => {
|
||||
/** Resolve a path composed only from inert literal syntax. */
|
||||
export const staticPath = (node: t.Node): string | undefined => {
|
||||
if (t.isStringLiteral(node)) return node.value;
|
||||
if (t.isTemplateLiteral(node) && node.expressions.length === 0)
|
||||
return stringValue(node);
|
||||
if (t.isBinaryExpression(node, { operator: "+" })) {
|
||||
const left = staticPathAt(node.left);
|
||||
const right = staticPathAt(node.right);
|
||||
const left = staticPath(node.left);
|
||||
const right = staticPath(node.right);
|
||||
return left === undefined || right === undefined
|
||||
? undefined
|
||||
: `${left}${right}`;
|
||||
@@ -215,7 +212,7 @@ const staticCallPath = (
|
||||
const parts: string[] = [];
|
||||
for (const argument of node.arguments) {
|
||||
if (isDirectoryIdentity(argumentNode(argument))) continue;
|
||||
const value = t.isNode(argument) ? staticPathAt(argument) : undefined;
|
||||
const value = t.isNode(argument) ? staticPath(argument) : undefined;
|
||||
if (value === undefined) return undefined;
|
||||
parts.push(value);
|
||||
}
|
||||
@@ -228,7 +225,7 @@ const staticFileUrlPath = (
|
||||
if (argument === undefined) return undefined;
|
||||
return isSourceFileUrl(argument)
|
||||
? sourceRelativeFileUrlPath(argument)
|
||||
: staticPathAt(argument);
|
||||
: staticPath(argument);
|
||||
};
|
||||
|
||||
/** Project a known source-relative URL through the actual file URL decoder. */
|
||||
@@ -284,7 +281,7 @@ const staticResolvedPath = (
|
||||
parts.push(null);
|
||||
continue;
|
||||
}
|
||||
const value = t.isNode(argument) ? staticPathAt(argument) : undefined;
|
||||
const value = t.isNode(argument) ? staticPath(argument) : undefined;
|
||||
// Validate every argument, including those before the last anchor.
|
||||
if (value === undefined) return undefined;
|
||||
parts.push(value);
|
||||
@@ -684,7 +681,7 @@ export const sortedUnique = <Value>(
|
||||
key: (value: Value) => string,
|
||||
): Value[] =>
|
||||
[...new Map(values.map((value) => [key(value), value])).values()].sort(
|
||||
(left, right) => compareCodePoints(key(left), key(right)),
|
||||
(left, right) => compareUnicodeCodePoints(key(left), key(right)),
|
||||
);
|
||||
|
||||
/** Hash exact UTF-8 source text. */
|
||||
|
||||
Reference in New Issue
Block a user