diff --git a/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/array-flatmap-reactive-deps.expect.md b/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/array-flatmap-reactive-deps.expect.md new file mode 100644 index 000000000000..bd13ef5d6d7e --- /dev/null +++ b/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/array-flatmap-reactive-deps.expect.md @@ -0,0 +1,82 @@ + +## Input + +```javascript +function Component(props) { + const cells = props.items.flatMap(item => [item, item.id + props.suffix]); + return ( +
+ {cells.map((cell, i) => ( + {typeof cell === 'object' ? cell.id : cell} + ))} +
+ ); +} + +export const FIXTURE_ENTRYPOINT = { + fn: Component, + params: [ + { + items: [{id: 1}, {id: 2}], + suffix: '-x', + }, + ], + isComponent: true, +}; + +``` + +## Code + +```javascript +import { c as _c } from "react/compiler-runtime"; +function Component(props) { + const $ = _c(7); + let t0; + if ($[0] !== props.items || $[1] !== props.suffix) { + let t1; + if ($[3] !== props.suffix) { + t1 = (item) => [item, item.id + props.suffix]; + $[3] = props.suffix; + $[4] = t1; + } else { + t1 = $[4]; + } + const cells = props.items.flatMap(t1); + t0 = cells.map(_temp); + $[0] = props.items; + $[1] = props.suffix; + $[2] = t0; + } else { + t0 = $[2]; + } + let t1; + if ($[5] !== t0) { + t1 =
{t0}
; + $[5] = t0; + $[6] = t1; + } else { + t1 = $[6]; + } + return t1; +} +function _temp(cell, i) { + return {typeof cell === "object" ? cell.id : cell}; +} + +export const FIXTURE_ENTRYPOINT = { + fn: Component, + params: [ + { + items: [{ id: 1 }, { id: 2 }], + suffix: "-x", + }, + ], + + isComponent: true, +}; + +``` + +### Eval output +(kind: ok)
11-x22-x
\ No newline at end of file diff --git a/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/array-flatmap-reactive-deps.js b/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/array-flatmap-reactive-deps.js new file mode 100644 index 000000000000..5d50bc061909 --- /dev/null +++ b/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/array-flatmap-reactive-deps.js @@ -0,0 +1,21 @@ +function Component(props) { + const cells = props.items.flatMap(item => [item, item.id + props.suffix]); + return ( +
+ {cells.map((cell, i) => ( + {typeof cell === 'object' ? cell.id : cell} + ))} +
+ ); +} + +export const FIXTURE_ENTRYPOINT = { + fn: Component, + params: [ + { + items: [{id: 1}, {id: 2}], + suffix: '-x', + }, + ], + isComponent: true, +};