From ffd72dde5f0677839a8eb973f625f5966ff4f325 Mon Sep 17 00:00:00 2001 From: Mike Vitousek Date: Thu, 18 Jul 2024 09:17:57 -0700 Subject: [PATCH] [compiler] Make compiler aware of whether a local binding is constlike or not Summary: Minor change which supports the changeDetection work later on. We can know whether an individual local binding is const or constlike. [ghstack-poisoned] --- compiler/packages/babel-plugin-react-compiler/src/HIR/HIR.ts | 2 +- .../babel-plugin-react-compiler/src/HIR/HIRBuilder.ts | 5 +++++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/compiler/packages/babel-plugin-react-compiler/src/HIR/HIR.ts b/compiler/packages/babel-plugin-react-compiler/src/HIR/HIR.ts index b79414de031..1f4a55d248a 100644 --- a/compiler/packages/babel-plugin-react-compiler/src/HIR/HIR.ts +++ b/compiler/packages/babel-plugin-react-compiler/src/HIR/HIR.ts @@ -1168,7 +1168,7 @@ export type NonLocalBinding = imported: string; } // let, const, function, etc declared in the module but outside the current component/hook - | { kind: "ModuleLocal"; name: string } + | { kind: "ModuleLocal"; name: string; immutable: boolean } // an unresolved binding | { kind: "Global"; name: string }; diff --git a/compiler/packages/babel-plugin-react-compiler/src/HIR/HIRBuilder.ts b/compiler/packages/babel-plugin-react-compiler/src/HIR/HIRBuilder.ts index 0342d57ea31..0bab88c974c 100644 --- a/compiler/packages/babel-plugin-react-compiler/src/HIR/HIRBuilder.ts +++ b/compiler/packages/babel-plugin-react-compiler/src/HIR/HIRBuilder.ts @@ -271,9 +271,14 @@ export default class HIRBuilder { module: importDeclaration.node.source.value, }; } else { + const immutable = + (path.isVariableDeclaration() && path.node.kind === "const") || + path.isClassDeclaration() || + path.isClassExpression(); return { kind: "ModuleLocal", name: originalName, + immutable, }; } }