mirror of
https://github.com/morluto/rea
synced 2026-10-27 06:33:32 -04:00
43 lines
1.2 KiB
TypeScript
43 lines
1.2 KiB
TypeScript
import * as t from "@babel/types";
|
|
import {
|
|
semanticStaticPropertyKey,
|
|
unwrapJavaScriptExpression,
|
|
} from "./javascriptAstValues.js";
|
|
import { isUnmodifiedGlobalReference } from "./javascriptSemanticAmbientWrites.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])
|
|
);
|
|
};
|