Scopes with reassignments should still emit memo block
Lauren Tan committed
Feb 13, 2023 at 16:52 UTC
b5a0739e8c438e44c8205528728988a87a2d9b8c
2 files changed
+5
-3
compiler/forget/src/ReactiveScopes/CodegenReactiveFunction.ts
+4
-1
@@ -219,6 +219,9 @@ function codegenReactiveScope(
219
}
220
for (const reassignment of scope.reassignments) {
221
const index = cx.nextCacheIndex;
222
+ if (firstOutputIndex === null) {
223
+ firstOutputIndex = index;
224
+ }
225
const name = convertIdentifier(reassignment);
226
227
cacheStoreStatements.push(
@@ -252,7 +255,7 @@ function codegenReactiveScope(
255
if (testCondition === null) {
256
invariant(
257
firstOutputIndex !== null,
255
- "Expected scope '@%s' to have at least one output",
258
+ "Expected scope '@%s' to have at least one declaration",
259
scope.id
260
);
261
testCondition = t.binaryExpression(
compiler/forget/src/ReactiveScopes/PruneUnusedScopes.ts
+1
-2
@@ -31,8 +31,7 @@ class Transform extends ReactiveFunctionTransform<void> {
31
this.visitScope(scopeBlock, state);
32
if (
33
scopeBlock.scope.declarations.size === 0 &&
34
- (scopeBlock.scope.dependencies.size === 0 ||
35
- scopeBlock.scope.reassignments.size === 0)
34
+ scopeBlock.scope.reassignments.size === 0
35
) {
36
return { kind: "replace-many", value: scopeBlock.instructions };
37
} else {