diff --git a/compiler/packages/babel-plugin-react-forget/src/ReactiveScopes/PropagateScopeDependencies.ts b/compiler/packages/babel-plugin-react-forget/src/ReactiveScopes/PropagateScopeDependencies.ts index b2693578f8..062b4881b3 100644 --- a/compiler/packages/babel-plugin-react-forget/src/ReactiveScopes/PropagateScopeDependencies.ts +++ b/compiler/packages/babel-plugin-react-forget/src/ReactiveScopes/PropagateScopeDependencies.ts @@ -23,6 +23,7 @@ import { ReactiveScopeDependency, ReactiveTerminalStatement, ReactiveValue, + ScopeId, } from "../HIR/HIR"; import { eachInstructionValueOperand, @@ -75,18 +76,18 @@ type TemporariesUsedOutsideDefiningScope = { * tracks all relevant temporary declarations (currently LoadLocal and PropertyLoad) * and the scope where they are defined */ - declarations: Map; + declarations: Map; // temporaries used outside of their defining scope usedOutsideDeclaringScope: Set; }; class FindPromotedTemporaries extends ReactiveFunctionVisitor { - scopes: Array = []; + scopes: Array = []; override visitScope( scope: ReactiveScopeBlock, state: TemporariesUsedOutsideDefiningScope ): void { - this.scopes.push(scope.scope); + this.scopes.push(scope.scope.id); this.traverseScope(scope, state); this.scopes.pop(); } @@ -95,6 +96,9 @@ class FindPromotedTemporaries extends ReactiveFunctionVisitor component:\n' + + '\n' + + ' at WrapperTestComponent (/packages/snap/dist/sprout/evaluator.js:54:26)\n' + + '\n' + + 'Consider adding an error boundary to your tree to customize error handling behavior.\n' + + 'Visit https://reactjs.org/link/error-boundaries to learn more about error boundaries.'] \ No newline at end of file diff --git a/compiler/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/repro-no-value-for-temporary.js b/compiler/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/repro-no-value-for-temporary.js new file mode 100644 index 0000000000..41c4be9afb --- /dev/null +++ b/compiler/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/repro-no-value-for-temporary.js @@ -0,0 +1,7 @@ +// @flow @enableAssumeHooksFollowRulesOfReact @enableTransitivelyFreezeFunctionExpressions +function Component(listItem, thread) { + const isFoo = isFooThread(thread.threadType); + const body = useBar(listItem, [getBadgeText(listItem, isFoo)]); + + return body; +}