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 8ed71b5e62..2352dc189d 100644 --- a/compiler/packages/babel-plugin-react-compiler/src/HIR/BuildHIR.ts +++ b/compiler/packages/babel-plugin-react-compiler/src/HIR/BuildHIR.ts @@ -428,17 +428,6 @@ function lowerStatement( loc: id.parentPath.node.loc ?? GeneratedSource, }); continue; - } else if (!binding.path.get('id').isIdentifier()) { - builder.errors.push({ - severity: ErrorSeverity.Todo, - reason: 'Unsupported variable declaration type for hoisting', - description: `variable "${ - binding.identifier.name - }" declared with ${binding.path.get('id').type}`, - suggestions: null, - loc: id.parentPath.node.loc ?? GeneratedSource, - }); - continue; } else if ( binding.kind !== 'const' && binding.kind !== 'var' && diff --git a/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/hoist-destruct.expect.md b/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/hoist-destruct.expect.md new file mode 100644 index 0000000000..24711915e5 --- /dev/null +++ b/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/hoist-destruct.expect.md @@ -0,0 +1,62 @@ + +## Input + +```javascript +//@flow +component Foo() { + function foo() { + return ( +
+ {a} {z} {y} +
+ ); + } + const [a, {x: z, y = 10}] = [1, {x: 2}]; + return foo(); +} + +export const FIXTURE_ENTRYPOINT = { + fn: Foo, + params: [], +}; + +``` + +## Code + +```javascript +import { c as _c } from "react/compiler-runtime"; +function Foo() { + const $ = _c(1); + let t0; + if ($[0] === Symbol.for("react.memo_cache_sentinel")) { + const foo = function foo() { + return ( +
+ {a} {z} {y} +
+ ); + }; + + const [t1, t2] = [1, { x: 2 }]; + const a = t1; + const { x: t3, y: t4 } = t2; + const z = t3; + const y = t4 === undefined ? 10 : t4; + t0 = foo(); + $[0] = t0; + } else { + t0 = $[0]; + } + return t0; +} + +export const FIXTURE_ENTRYPOINT = { + fn: Foo, + params: [], +}; + +``` + +### Eval output +(kind: ok)
1 2 10
\ No newline at end of file diff --git a/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/hoist-destruct.js b/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/hoist-destruct.js new file mode 100644 index 0000000000..a1c5253494 --- /dev/null +++ b/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/hoist-destruct.js @@ -0,0 +1,17 @@ +//@flow +component Foo() { + function foo() { + return ( +
+ {a} {z} {y} +
+ ); + } + const [a, {x: z, y = 10}] = [1, {x: 2}]; + return foo(); +} + +export const FIXTURE_ENTRYPOINT = { + fn: Foo, + params: [], +};