diff --git a/compiler/packages/babel-plugin-react-compiler/src/HIR/BuildHIR.ts b/compiler/packages/babel-plugin-react-compiler/src/HIR/BuildHIR.ts index 44846e8205e91..6695e6b03204f 100644 --- a/compiler/packages/babel-plugin-react-compiler/src/HIR/BuildHIR.ts +++ b/compiler/packages/babel-plugin-react-compiler/src/HIR/BuildHIR.ts @@ -1909,11 +1909,19 @@ function lowerExpression( if (operator === '=') { const left = expr.get('left'); + + // OptionalMemberExpressions as the left side of an AssignmentExpression are not yet supported + if (left.isNodeType('OptionalMemberExpression')) { + CompilerError.throwTodo({ + reason: `Unsupported syntax: OptionalMemberExpression on the left side of an AssignmentExpression`, + loc: left.node.loc ?? null, + }); + } return lowerAssignment( builder, left.node.loc ?? GeneratedSource, InstructionKind.Reassign, - left, + left as NodePath, lowerExpressionToTemporary(builder, expr.get('right')), left.isArrayPattern() || left.isObjectPattern() ? 'Destructure' @@ -3545,7 +3553,7 @@ function lowerAssignment( builder: HIRBuilder, loc: SourceLocation, kind: InstructionKind, - lvaluePath: NodePath, + lvaluePath: NodePath, value: Place, assignmentKind: 'Destructure' | 'Assignment', ): InstructionValue { diff --git a/compiler/packages/babel-plugin-react-compiler/src/HIR/FindContextIdentifiers.ts b/compiler/packages/babel-plugin-react-compiler/src/HIR/FindContextIdentifiers.ts index 818d262fc9978..f59a63fbcdb77 100644 --- a/compiler/packages/babel-plugin-react-compiler/src/HIR/FindContextIdentifiers.ts +++ b/compiler/packages/babel-plugin-react-compiler/src/HIR/FindContextIdentifiers.ts @@ -63,8 +63,21 @@ export function findContextIdentifiers( state: FindContextIdentifierState, ): void { const left = path.get('left'); + + // OptionalMemberExpressions as the left side of an AssignmentExpression are not yet supported + if (left.isNodeType('OptionalMemberExpression')) { + CompilerError.throwTodo({ + reason: `Unsupported syntax: OptionalMemberExpression on the left side of an AssignmentExpression`, + loc: left.node.loc ?? null, + }); + } + const currentFn = state.currentFn.at(-1) ?? null; - handleAssignment(currentFn, state.identifiers, left); + handleAssignment( + currentFn, + state.identifiers, + left as NodePath, + ); }, UpdateExpression( path: NodePath, @@ -126,7 +139,7 @@ function handleIdentifier( function handleAssignment( currentFn: BabelFunction | null, identifiers: Map, - lvalPath: NodePath, + lvalPath: NodePath, ): void { /* * Find all reassignments to identifiers declared outside of currentFn