diff --git a/compiler/packages/babel-plugin-react-forget/src/ReactiveScopes/CodegenReactiveFunction.ts b/compiler/packages/babel-plugin-react-forget/src/ReactiveScopes/CodegenReactiveFunction.ts index 537730811d..396acc0f33 100644 --- a/compiler/packages/babel-plugin-react-forget/src/ReactiveScopes/CodegenReactiveFunction.ts +++ b/compiler/packages/babel-plugin-react-forget/src/ReactiveScopes/CodegenReactiveFunction.ts @@ -6,7 +6,12 @@ */ import * as t from "@babel/types"; -import { pruneUnusedLValues, pruneUnusedLabels, renameVariables } from "."; +import { + pruneHoistedContexts, + pruneUnusedLValues, + pruneUnusedLabels, + renameVariables, +} from "."; import { CompilerError, ErrorSeverity } from "../CompilerError"; import { Environment, EnvironmentConfig, ExternalFunction } from "../HIR"; import { @@ -1514,6 +1519,7 @@ function codegenInstructionValue( pruneUnusedLabels(reactiveFunction); pruneUnusedLValues(reactiveFunction); renameVariables(reactiveFunction); + pruneHoistedContexts(reactiveFunction); const fn = codegenReactiveFunction(reactiveFunction, cx).unwrap(); if (instrValue.expr.type === "ArrowFunctionExpression") { let body: t.BlockStatement | t.Expression = fn.body; diff --git a/compiler/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/hoisting-within-lambda.expect.md b/compiler/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/hoisting-within-lambda.expect.md new file mode 100644 index 0000000000..77b679730c --- /dev/null +++ b/compiler/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/hoisting-within-lambda.expect.md @@ -0,0 +1,60 @@ + +## Input + +```javascript +function Component({}) { + const outer = () => { + const inner = () => { + return x; + }; + const x = 3; + return inner(); + }; + return