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 772fa61fbc5bc..3244eaf47837c 100644 --- a/compiler/packages/babel-plugin-react-compiler/src/HIR/BuildHIR.ts +++ b/compiler/packages/babel-plugin-react-compiler/src/HIR/BuildHIR.ts @@ -1520,6 +1520,15 @@ function lowerExpression( place, }); } else if (propertyPath.isObjectMethod()) { + if (propertyPath.node.kind !== "method") { + builder.errors.push({ + reason: `(BuildHIR::lowerExpression) Handle ${propertyPath.node.kind} functions in ObjectExpression`, + severity: ErrorSeverity.Todo, + loc: propertyPath.node.loc ?? null, + suggestions: null, + }); + continue; + } const method = lowerObjectMethod(builder, propertyPath); const place = lowerValueToTemporary(builder, method); const loweredKey = lowerObjectPropertyKey(builder, propertyPath); diff --git a/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/error.todo-object-expression-get-syntax.expect.md b/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/error.todo-object-expression-get-syntax.expect.md new file mode 100644 index 0000000000000..d713d07fd24d5 --- /dev/null +++ b/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/error.todo-object-expression-get-syntax.expect.md @@ -0,0 +1,39 @@ + +## Input + +```javascript +function Component({ value }) { + const object = { + get value() { + return value; + }, + }; + return
{object.value}
; +} + +export const FIXTURE_ENTRYPOINT = { + fn: foo, + params: [{ value: 0 }], + sequentialRenders: [{ value: 1 }, { value: 2 }], +}; + +``` + + +## Error + +``` + 1 | function Component({ value }) { + 2 | const object = { +> 3 | get value() { + | ^^^^^^^^^^^^^ +> 4 | return value; + | ^^^^^^^^^^^^^^^^^^^ +> 5 | }, + | ^^^^^^ Todo: (BuildHIR::lowerExpression) Handle get functions in ObjectExpression (3:5) + 6 | }; + 7 | return
{object.value}
; + 8 | } +``` + + \ No newline at end of file diff --git a/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/error.todo-object-expression-get-syntax.js b/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/error.todo-object-expression-get-syntax.js new file mode 100644 index 0000000000000..e96134edf1b9b --- /dev/null +++ b/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/error.todo-object-expression-get-syntax.js @@ -0,0 +1,14 @@ +function Component({ value }) { + const object = { + get value() { + return value; + }, + }; + return
{object.value}
; +} + +export const FIXTURE_ENTRYPOINT = { + fn: foo, + params: [{ value: 0 }], + sequentialRenders: [{ value: 1 }, { value: 2 }], +}; diff --git a/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/error.todo-object-expression-set-syntax.expect.md b/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/error.todo-object-expression-set-syntax.expect.md new file mode 100644 index 0000000000000..1d917b4d3ac2a --- /dev/null +++ b/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/error.todo-object-expression-set-syntax.expect.md @@ -0,0 +1,41 @@ + +## Input + +```javascript +function Component(props) { + let value; + const object = { + set value(v) { + value = v; + }, + }; + object.value = props.value; + return
{value}
; +} + +export const FIXTURE_ENTRYPOINT = { + fn: foo, + params: [{ value: 0 }], + sequentialRenders: [{ value: 1 }, { value: 2 }], +}; + +``` + + +## Error + +``` + 2 | let value; + 3 | const object = { +> 4 | set value(v) { + | ^^^^^^^^^^^^^^ +> 5 | value = v; + | ^^^^^^^^^^^^^^^^ +> 6 | }, + | ^^^^^^ Todo: (BuildHIR::lowerExpression) Handle set functions in ObjectExpression (4:6) + 7 | }; + 8 | object.value = props.value; + 9 | return
{value}
; +``` + + \ No newline at end of file diff --git a/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/error.todo-object-expression-set-syntax.js b/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/error.todo-object-expression-set-syntax.js new file mode 100644 index 0000000000000..5030bea6fc6af --- /dev/null +++ b/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/error.todo-object-expression-set-syntax.js @@ -0,0 +1,16 @@ +function Component(props) { + let value; + const object = { + set value(v) { + value = v; + }, + }; + object.value = props.value; + return
{value}
; +} + +export const FIXTURE_ENTRYPOINT = { + fn: foo, + params: [{ value: 0 }], + sequentialRenders: [{ value: 1 }, { value: 2 }], +};