@samitouri / QOS-React-2 / commits / 59a1f2a5b0

AnalyzeFunction: ref values take priority over other mutations

Small tweak necessary for the subsequent PRs, refs and ref values take precedence over other mutations when computing the effect type of context variables. We always want to record ref access within a function as capture (since we have later validation) rather than a mutation. For now this has no impact, either order records a Capture. But it allows later diffs to make non-ref cases have other effects.

Joe Savona committed Jun 16, 2023 at 14:42 UTC 59a1f2a5b00bd6fa81c5dc6494fb691ee6db86d6
1 file changed +3 -3
compiler/forget/packages/babel-plugin-react-forget/src/Inference/AnalyseFunctions.ts
+3 -3
@@ -126,15 +126,15 @@ function infer(
126 name = dep.identifier.name;
127 }
128
129 - if (name !== null && mutations.has(name)) {
130 - dep.effect = Effect.Capture;
131 - } else if (isUseRefType(dep.identifier) || isRefValueType(dep.identifier)) {
129 + if (isUseRefType(dep.identifier) || isRefValueType(dep.identifier)) {
130 // TODO: this is a hack to ensure we treat functions which reference refs
131 // as having a capture and therefore being considered mutable. this ensures
132 // the function gets a mutable range which accounts for anywhere that it
133 // could be called, and allows us to help ensure it isn't called during
134 // render
135 dep.effect = Effect.Capture;
136 + } else if (name !== null && mutations.has(name)) {
137 + dep.effect = Effect.Capture;
138 }
139 }
140