mirror of
https://github.com/morluto/rea
synced 2026-10-28 15:07:26 -04:00
chore: merge main into audited lifecycle fixes
This commit is contained in:
@@ -482,6 +482,25 @@ const directMutationPosition = (
|
||||
return computed;
|
||||
};
|
||||
|
||||
/** Prove that an unconditional member replacement precedes this read. */
|
||||
export const semanticDefiniteEffectPrecedesReference = (
|
||||
effect: t.Node,
|
||||
reference: t.Node,
|
||||
parents: WeakMap<t.Node, t.Node>,
|
||||
): boolean => {
|
||||
const before = directMutationPosition(effect, parents);
|
||||
const after = bindingReadPosition(reference, parents);
|
||||
if (before === null || after.position === null || after.repeating)
|
||||
return false;
|
||||
if (positionPrecedes(before, after.position)) return true;
|
||||
return (
|
||||
before.body === after.position.body &&
|
||||
before.index === after.position.index &&
|
||||
before.declaratorIndex === after.position.declaratorIndex &&
|
||||
expressionEvaluationOrder(effect, reference, parents) === "before"
|
||||
);
|
||||
};
|
||||
|
||||
const computeReferenceInitializerPosition = (
|
||||
node: t.Node,
|
||||
parents: WeakMap<t.Node, t.Node>,
|
||||
@@ -492,6 +511,11 @@ const computeReferenceInitializerPosition = (
|
||||
const direct = directInitializerPosition(current, parents);
|
||||
if (direct !== null) return direct;
|
||||
const parent = parents.get(current);
|
||||
if (
|
||||
t.isAssignmentExpression(parent, { operator: "=" }) &&
|
||||
(t.isObjectPattern(parent.left) || t.isArrayPattern(parent.left))
|
||||
)
|
||||
return directMutationPosition(parent, parents);
|
||||
if (t.isFunction(parent))
|
||||
return t.isBlockStatement(parent.body)
|
||||
? { body: parent.body.body, index: -1, declaratorIndex: -1 }
|
||||
@@ -682,8 +706,15 @@ export const semanticBindingAtRead = (
|
||||
// can cover entry even when another write's order remains unknown.
|
||||
const hasDefiniteInitializer =
|
||||
position !== null &&
|
||||
binding.initializers.some((initializer) => {
|
||||
const source = initializerPosition(initializer, parents);
|
||||
[
|
||||
...binding.initializers,
|
||||
...binding.referenceInitializers.filter(({ assignment }) => assignment),
|
||||
].some((initializer) => {
|
||||
const source = initializerPosition(
|
||||
initializer,
|
||||
parents,
|
||||
binding.referenceInitializers.includes(initializer),
|
||||
);
|
||||
return (
|
||||
source !== null &&
|
||||
positionPrecedes(source, position) &&
|
||||
|
||||
Reference in New Issue
Block a user