From b0d2b0093f0ad6b915a6109151c6429d2b00a925 Mon Sep 17 00:00:00 2001 From: Raashish Aggarwal <94279692+raashish1601@users.noreply.github.com> Date: Sat, 2 May 2026 10:45:20 +0530 Subject: [PATCH] Add props object location callback fixture --- ...ps-object-with-location-callback.expect.md | 102 ++++++++++++++++++ .../props-object-with-location-callback.js | 26 +++++ 2 files changed, 128 insertions(+) create mode 100644 compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/props-object-with-location-callback.expect.md create mode 100644 compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/props-object-with-location-callback.js diff --git a/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/props-object-with-location-callback.expect.md b/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/props-object-with-location-callback.expect.md new file mode 100644 index 000000000000..9f484dcac244 --- /dev/null +++ b/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/props-object-with-location-callback.expect.md @@ -0,0 +1,102 @@ + +## Input + +```javascript +function MiniCarousel(props) { + return
{props.cards.length}
; +} + +function Component(props) { + const cardListTransformed = props.cards.map(card => ({ + ...card, + slug: card.slug.toLowerCase(), + })); + const miniCarouselProps = { + ...props, + cards: cardListTransformed, + slug: props.locationSlug, + onCardClick: card => { + location.pathname = card.slug; + }, + forceAnchorTag: false, + }; + + return ; +} + +export const FIXTURE_ENTRYPOINT = { + fn: Component, + params: [{cards: [{slug: 'A'}], locationSlug: 'home'}], +}; + +``` + +## Code + +```javascript +import { c as _c } from "react/compiler-runtime"; +function MiniCarousel(props) { + const $ = _c(2); + let t0; + if ($[0] !== props.cards.length) { + t0 =
{props.cards.length}
; + $[0] = props.cards.length; + $[1] = t0; + } else { + t0 = $[1]; + } + return t0; +} + +function Component(props) { + const $ = _c(6); + let t0; + if ($[0] !== props.cards) { + t0 = props.cards.map(_temp); + $[0] = props.cards; + $[1] = t0; + } else { + t0 = $[1]; + } + const cardListTransformed = t0; + let t1; + if ($[2] === Symbol.for("react.memo_cache_sentinel")) { + t1 = _temp2; + $[2] = t1; + } else { + t1 = $[2]; + } + let t2; + if ($[3] !== cardListTransformed || $[4] !== props) { + const miniCarouselProps = { + ...props, + cards: cardListTransformed, + slug: props.locationSlug, + onCardClick: t1, + forceAnchorTag: false, + }; + t2 = ; + $[3] = cardListTransformed; + $[4] = props; + $[5] = t2; + } else { + t2 = $[5]; + } + return t2; +} +function _temp2(card_0) { + location.pathname = card_0.slug; +} +function _temp(card) { + return { ...card, slug: card.slug.toLowerCase() }; +} + +export const FIXTURE_ENTRYPOINT = { + fn: Component, + params: [{ cards: [{ slug: "A" }], locationSlug: "home" }], +}; + +``` + +### Eval output +(kind: ok)
1
\ No newline at end of file diff --git a/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/props-object-with-location-callback.js b/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/props-object-with-location-callback.js new file mode 100644 index 000000000000..112c416fe495 --- /dev/null +++ b/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/props-object-with-location-callback.js @@ -0,0 +1,26 @@ +function MiniCarousel(props) { + return
{props.cards.length}
; +} + +function Component(props) { + const cardListTransformed = props.cards.map(card => ({ + ...card, + slug: card.slug.toLowerCase(), + })); + const miniCarouselProps = { + ...props, + cards: cardListTransformed, + slug: props.locationSlug, + onCardClick: card => { + location.pathname = card.slug; + }, + forceAnchorTag: false, + }; + + return ; +} + +export const FIXTURE_ENTRYPOINT = { + fn: Component, + params: [{cards: [{slug: 'A'}], locationSlug: 'home'}], +};