diff --git a/compiler/packages/babel-plugin-react-forget/src/HIR/BuildHIR.ts b/compiler/packages/babel-plugin-react-forget/src/HIR/BuildHIR.ts index 9425030dac..33158cbbd6 100644 --- a/compiler/packages/babel-plugin-react-forget/src/HIR/BuildHIR.ts +++ b/compiler/packages/babel-plugin-react-forget/src/HIR/BuildHIR.ts @@ -366,7 +366,12 @@ function lowerStatement( ArrowFunctionExpression: withFunctionContext, ObjectMethod: withFunctionContext, Identifier(id: NodePath) { - if (!id.isReferencedIdentifier()) { + const id2 = id; + if ( + !id2.isReferencedIdentifier() && + // isReferencedIdentifier is broken and returns false for reassignments + id.parent.type !== "AssignmentExpression" + ) { return; } const binding = id.scope.getBinding(id.node.name); diff --git a/compiler/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/error.todo-function-expression-references-later-variable-declaration.expect.md b/compiler/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/error.todo-function-expression-references-later-variable-declaration.expect.md index 797ea6a278..d674395e54 100644 --- a/compiler/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/error.todo-function-expression-references-later-variable-declaration.expect.md +++ b/compiler/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/error.todo-function-expression-references-later-variable-declaration.expect.md @@ -20,7 +20,7 @@ function Component() { 1 | function Component() { 2 | let callback = () => { > 3 | onClick = () => {}; - | ^^^^^^^ [ReactForget] Invariant: [hoisting] Expected value kind to be initialized. read onClick$0_@1 (3:3) + | ^^^^^^^^^^^^^^^^^^ [ReactForget] Todo: Handle non-const declarations for hoisting. variable "onClick" declared with let (3:3) 4 | }; 5 | let onClick; 6 | diff --git a/compiler/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/error.todo-function-expression-references-variable-its-assigned-to.expect.md b/compiler/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/error.todo-function-expression-references-variable-its-assigned-to.expect.md index 209f6bf447..db960286f4 100644 --- a/compiler/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/error.todo-function-expression-references-variable-its-assigned-to.expect.md +++ b/compiler/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/error.todo-function-expression-references-variable-its-assigned-to.expect.md @@ -18,7 +18,7 @@ function Component() { 1 | function Component() { 2 | let callback = () => { > 3 | callback = null; - | ^^^^^^^^ [ReactForget] Invariant: [hoisting] Expected value kind to be initialized. read callback$0_@0 (3:3) + | ^^^^^^^^^^^^^^^ [ReactForget] Todo: Handle non-const declarations for hoisting. variable "callback" declared with let (3:3) 4 | }; 5 | return
; 6 | }