mirror of
https://github.com/morluto/rea.git
synced 2026-11-20 05:32:44 +00:00
fix(javascript): preserve nested array iterator dependencies (#12558)
* fix(javascript): preserve nested array iterator dependencies * fix(javascript): retain reflected array prototype identity * fix(javascript): guard native arrays with ambient prototype effects Reuse the shared effect-log classifier first prepared for dense inline spread analysis. * test(javascript): keep array prototype alias fixture with sources
This commit is contained in:
1 parent
a035813e55
commit
473b3ee10e
8 files changed
+256
-33
No files matched your search
@@ -11,6 +11,7 @@ import {
|
||||
unwrapJavaScriptExpression,
|
||||
} from "./javascriptAstValues.js";
|
||||
import {
|
||||
semanticArrayIndex,
|
||||
semanticPropertyPathKeyMatches,
|
||||
type JavaScriptSemanticPropertyPath,
|
||||
} from "./javascriptSemanticPropertyPaths.js";
|
||||
@@ -377,6 +378,38 @@ export const semanticEffectMayFollow = (
|
||||
type AmbientEffect =
|
||||
JavaScriptSemanticAnalysisState["ambientWriteEffects"][number];
|
||||
|
||||
/** Which effects on the native prototype chain can alter array iteration. */
|
||||
export const semanticArrayPrototypeIterationMayChange = (
|
||||
path: JavaScriptSemanticPropertyPath,
|
||||
): boolean => {
|
||||
let offset = 0;
|
||||
while (path[offset] === "constructor" && path[offset + 1] === "prototype")
|
||||
offset += 2;
|
||||
const key = path[offset];
|
||||
return (
|
||||
key === undefined ||
|
||||
key === null ||
|
||||
typeof key === "object" ||
|
||||
semanticArrayIndex(key) !== null ||
|
||||
key === "__proto__"
|
||||
);
|
||||
};
|
||||
|
||||
/** Seed the iteration guard from the earlier, alias-aware ambient effect index. */
|
||||
export const semanticAmbientArrayIterationUnknown = (
|
||||
state: JavaScriptSemanticAnalysisState,
|
||||
): boolean => {
|
||||
const changesIteration = ({ path }: AmbientEffect): boolean =>
|
||||
path[0] === "global" &&
|
||||
(path[1] === "Array" || path[1] === "Object" || path[1] === null) &&
|
||||
(path[2] === "prototype" || path[2] === null) &&
|
||||
semanticArrayPrototypeIterationMayChange(path.slice(3));
|
||||
return (
|
||||
state.ambientWriteEffects.some(changesIteration) ||
|
||||
state.ambientEscapeEffects.some(changesIteration)
|
||||
);
|
||||
};
|
||||
|
||||
type MemberWrite = JavaScriptSemanticBindingState["memberWrites"][number];
|
||||
|
||||
/** Matching effects per queried path; the effect lists only grow, so their
|
||||
|
||||
Reference in new issue
Block a user