Files
reverse-engineering-anything/src/domain/javascript/javascriptSemanticPropertyKeys.ts
T
morlutoandCursor Agent 249b90c5e3 refactor(javascript): break the semantic analysis import cycle (#8063)
* refactor(javascript): break the semantic analysis import cycle

Split shared semantic facts out of the analysis hub so projectors of
effects, evaluation, and identity no longer import one another in a cycle.

* refactor(javascript): share the import specifier reader

Read static imports in one module used by the boundary checker and both
cycle guards, so those rules cannot drift apart.

---------

Co-authored-by: Cursor Agent <cursoragent@cursor.com>
2026-10-30 06:07:49 +08:00

43 lines
1.2 KiB
TypeScript

import * as t from "@babel/types";
import {
semanticStaticPropertyKey,
unwrapJavaScriptExpression,
} from "./javascriptAstValues.js";
import { isUnmodifiedGlobalReference } from "./javascriptSemanticGlobalReference.js";
import type { JavaScriptSemanticAnalysisState } from "./javascriptSemanticState.js";
// These intrinsic properties hold symbols, so ToPropertyKey cannot produce a
// string slot. Visible replacement of Symbol/the selected property voids proof.
const wellKnownSymbols = new Set([
"asyncIterator",
"hasInstance",
"isConcatSpreadable",
"iterator",
"match",
"matchAll",
"replace",
"search",
"species",
"split",
"toPrimitive",
"toStringTag",
"unscopables",
"dispose",
"asyncDispose",
]);
/** A proved symbol key cannot shadow a selected string property. */
export const semanticKnownSymbolKey = (
node: t.Node,
state: JavaScriptSemanticAnalysisState,
): boolean => {
const key = unwrapJavaScriptExpression(node).node;
if (!t.isMemberExpression(key)) return false;
const name = semanticStaticPropertyKey(key.property, key.computed);
return (
name !== null &&
wellKnownSymbols.has(name) &&
isUnmodifiedGlobalReference(key, state, ["Symbol", name])
);
};