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 b79414de03..1f4a55d248 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 0342d57ea3..0bab88c974 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, }; } }