@samitouri / QOS-React-2 / commits / e35df45eaf

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.

Sathya Gunasekaran committed Nov 9, 2023 at 10:30 UTC e35df45eaf0ffb79cb9b1c738bafc972f3aaeb9d
2 files changed +57
compiler/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/gating-access-function-name-in-component.expect.md new
+47
@@ -0,0 +1,47 @@
1 +
2 +## Input
3 +
4 +```javascript
5 +// @gating
6 +function Component() {
7 + const name = Component.name;
8 + return <div>{name}</div>;
9 +}
10 +
11 +export const FIXTURE_ENTRYPOINT = {
12 + fn: Component,
13 + params: [],
14 +};
15 +
16 +```
17 +
18 +## Code
19 +
20 +```javascript
21 +import { isForgetEnabled_Fixtures } from "ReactForgetFeatureFlag";
22 +import { unstable_useMemoCache as useMemoCache } from "react"; // @gating
23 +const Component = isForgetEnabled_Fixtures()
24 + ? function Component() {
25 + const $ = useMemoCache(1);
26 + const name = Component.name;
27 + let t0;
28 + if ($[0] === Symbol.for("react.memo_cache_sentinel")) {
29 + t0 = <div>{name}</div>;
30 + $[0] = t0;
31 + } else {
32 + t0 = $[0];
33 + }
34 + return t0;
35 + }
36 + : function Component() {
37 + const name = Component.name;
38 + return <div>{name}</div>;
39 + };
40 +
41 +export const FIXTURE_ENTRYPOINT = {
42 + fn: Component,
43 + params: [],
44 +};
45 +
46 +```
47 +
\ No newline at end of file
compiler/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/gating-access-function-name-in-component.js new
+10
@@ -0,0 +1,10 @@
1 +// @gating
2 +function Component() {
3 + const name = Component.name;
4 + return <div>{name}</div>;
5 +}
6 +
7 +export const FIXTURE_ENTRYPOINT = {
8 + fn: Component,
9 + params: [],
10 +};