mirror of
https://github.com/morluto/rea.git
synced 2026-11-20 05:32:44 +00:00
fix(javascript): acquire nested iterators from stored receivers (#12542)
* fix(javascript): acquire nested iterators from stored receivers * fix(javascript): preserve stored iterator branches and pattern timing
This commit is contained in:
1 parent
4892615ecb
commit
f5573a0064
8 files changed
+490
-65
No files matched your search
@@ -27,6 +27,7 @@ import {
|
||||
} from "./javascriptSemanticEffectPathIndex.js";
|
||||
import {
|
||||
isUnshadowedGlobal,
|
||||
isSemanticArrayPatternEffect,
|
||||
semanticBindingEffectFollowsCapture,
|
||||
semanticEscapeFollowsCapture,
|
||||
semanticDefiniteEffectPrecedesReference,
|
||||
@@ -581,6 +582,27 @@ export const bindingMemberEffectMayPrecedeReads = (
|
||||
return false;
|
||||
};
|
||||
|
||||
/** Whether a selected receiver's contents can change before use.
|
||||
* Writes replacing the receiver are covered by the source-selection query.
|
||||
*/
|
||||
export const bindingProjectedContentsMayChangeAt = (
|
||||
state: JavaScriptSemanticAnalysisState,
|
||||
binding: JavaScriptSemanticBindingState,
|
||||
path: JavaScriptSemanticPropertyPath,
|
||||
read: t.Node,
|
||||
): boolean =>
|
||||
opaqueCodeMayReachBindingReference(binding, state, read) ||
|
||||
bindingMemberEffectMayPrecedeReads(
|
||||
state,
|
||||
binding,
|
||||
(kind, effect) =>
|
||||
(kind === "escape" || effect.path.length > path.length) &&
|
||||
semanticEffectPathMatches(effect.path.slice(0, path.length), path)
|
||||
? [read]
|
||||
: undefined,
|
||||
"activation",
|
||||
);
|
||||
|
||||
/**
|
||||
* Whether an assignment to `binding` recorded as a reference initializer
|
||||
* (a pattern or other non-ordinary write) may run before `read`.
|
||||
@@ -1031,6 +1053,37 @@ export const capturedBindingPathMayHaveChanged = (
|
||||
);
|
||||
};
|
||||
|
||||
/** Preserve an own-data read when the only possible changes follow it in an iterator phase. */
|
||||
export const bindingPathOnlyEscapesAtLaterIteratorEffects = (
|
||||
binding: JavaScriptSemanticBindingState,
|
||||
path: readonly string[],
|
||||
read: t.Node,
|
||||
state: JavaScriptSemanticAnalysisState,
|
||||
): boolean => {
|
||||
let laterIterator = false;
|
||||
const matches = (effect: JavaScriptSemanticMemberEffect): boolean =>
|
||||
semanticEffectPathMatches(effect.path, path);
|
||||
if (
|
||||
semanticSomeEffectPathCandidate(binding.escapedPaths, path, (effect) => {
|
||||
if (!matches(effect)) return false;
|
||||
if (
|
||||
!isSemanticArrayPatternEffect(effect.node) ||
|
||||
semanticEffectTiming(read, effect.node, state) !== "after"
|
||||
)
|
||||
return true;
|
||||
laterIterator = true;
|
||||
return false;
|
||||
}) ||
|
||||
!laterIterator
|
||||
)
|
||||
return false;
|
||||
return (
|
||||
!opaqueCodeMayReachBindingReference(binding, state, read) &&
|
||||
!semanticOpaqueGlobalMayHaveChanged(read, state) &&
|
||||
!semanticSomeEffectPathCandidate(binding.memberWrites, path, matches)
|
||||
);
|
||||
};
|
||||
|
||||
/**
|
||||
* The value of `binding`'s reference as a read captured at `capturePoint`
|
||||
* observes it, after the recorded effects that may precede the capture:
|
||||
|
||||
Reference in new issue
Block a user