From e35df45eaf0ffb79cb9b1c738bafc972f3aaeb9d Mon Sep 17 00:00:00 2001 From: Sathya Gunasekaran Date: Thu, 9 Nov 2023 10:30:54 +0000 Subject: [PATCH] Test component name access in gated setup Jesse flagged this as a potential bug internally but this looks correct to me. Adding a test case so that we don't regress in the future. --- ...ccess-function-name-in-component.expect.md | 47 +++++++++++++++++++ ...ating-access-function-name-in-component.js | 10 ++++ 2 files changed, 57 insertions(+) create mode 100644 compiler/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/gating-access-function-name-in-component.expect.md create mode 100644 compiler/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/gating-access-function-name-in-component.js diff --git a/compiler/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/gating-access-function-name-in-component.expect.md b/compiler/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/gating-access-function-name-in-component.expect.md new file mode 100644 index 0000000000..15bbcb5930 --- /dev/null +++ b/compiler/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/gating-access-function-name-in-component.expect.md @@ -0,0 +1,47 @@ + +## Input + +```javascript +// @gating +function Component() { + const name = Component.name; + return
{name}
; +} + +export const FIXTURE_ENTRYPOINT = { + fn: Component, + params: [], +}; + +``` + +## Code + +```javascript +import { isForgetEnabled_Fixtures } from "ReactForgetFeatureFlag"; +import { unstable_useMemoCache as useMemoCache } from "react"; // @gating +const Component = isForgetEnabled_Fixtures() + ? function Component() { + const $ = useMemoCache(1); + const name = Component.name; + let t0; + if ($[0] === Symbol.for("react.memo_cache_sentinel")) { + t0 =
{name}
; + $[0] = t0; + } else { + t0 = $[0]; + } + return t0; + } + : function Component() { + const name = Component.name; + return
{name}
; + }; + +export const FIXTURE_ENTRYPOINT = { + fn: Component, + params: [], +}; + +``` + \ No newline at end of file diff --git a/compiler/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/gating-access-function-name-in-component.js b/compiler/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/gating-access-function-name-in-component.js new file mode 100644 index 0000000000..f6c5fc813e --- /dev/null +++ b/compiler/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/gating-access-function-name-in-component.js @@ -0,0 +1,10 @@ +// @gating +function Component() { + const name = Component.name; + return
{name}
; +} + +export const FIXTURE_ENTRYPOINT = { + fn: Component, + params: [], +};