From 4571979e4685aaf0e42f0f24200e52059af7a4fd Mon Sep 17 00:00:00 2001 From: Sathya Gunasekaran Date: Tue, 5 Sep 2023 11:13:30 +0100 Subject: [PATCH] Add pass to lower useState --- .../src/Entrypoint/Pipeline.ts | 10 ++++++++++ .../src/ReactiveScopes/index.ts | 6 ++++++ 2 files changed, 16 insertions(+) diff --git a/compiler/packages/babel-plugin-react-forget/src/Entrypoint/Pipeline.ts b/compiler/packages/babel-plugin-react-forget/src/Entrypoint/Pipeline.ts index f86743c1c3..0ae11aafe7 100644 --- a/compiler/packages/babel-plugin-react-forget/src/Entrypoint/Pipeline.ts +++ b/compiler/packages/babel-plugin-react-forget/src/Entrypoint/Pipeline.ts @@ -7,6 +7,7 @@ import { NodePath } from "@babel/traverse"; import * as t from "@babel/types"; +import { lowerUseState } from "../Forest"; import { HIRFunction, ReactiveFunction, @@ -245,6 +246,15 @@ export function* run( value: reactiveFunction, }); + if (config?.enableForest) { + lowerUseState(reactiveFunction); + yield log({ + kind: "reactive", + name: "LowerUseState", + value: reactiveFunction, + }); + } + promoteUsedTemporaries(reactiveFunction); yield log({ kind: "reactive", diff --git a/compiler/packages/babel-plugin-react-forget/src/ReactiveScopes/index.ts b/compiler/packages/babel-plugin-react-forget/src/ReactiveScopes/index.ts index 698dc600fb..5de4cc9424 100644 --- a/compiler/packages/babel-plugin-react-forget/src/ReactiveScopes/index.ts +++ b/compiler/packages/babel-plugin-react-forget/src/ReactiveScopes/index.ts @@ -28,3 +28,9 @@ export { pruneTemporaryLValues as pruneUnusedLValues } from "./PruneTemporaryLVa export { pruneUnusedLabels } from "./PruneUnusedLabels"; export { pruneUnusedScopes } from "./PruneUnusedScopes"; export { renameVariables } from "./RenameVariables"; +export { + ReactiveFunctionTransform, + Transformed, + eachReactiveValueOperand, + visitReactiveFunction, +} from "./visitors";