@samitouri / QOS-React-2 / commits / 2927792dca

Extra tests for #2339

Joe Savona committed Nov 10, 2023 at 09:25 UTC 2927792dca1f7339a8c3777961786103d77aec46
4 files changed +147
compiler/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/mege-consecutive-scopes-dont-merge-with-different-deps.expect.md new
+67
@@ -0,0 +1,67 @@
1 +
2 +## Input
3 +
4 +```javascript
5 +const { getNumber, identity } = require("shared-runtime");
6 +
7 +function Component(props) {
8 + // Two scopes: one for `getNumber()`, one for the object literal.
9 + // Neither has dependencies so they should merge
10 + return { a: getNumber(), b: identity(props.id), c: ["static"] };
11 +}
12 +
13 +export const FIXTURE_ENTRYPOINT = {
14 + fn: Component,
15 + params: [{ id: 42 }],
16 +};
17 +
18 +```
19 +
20 +## Code
21 +
22 +```javascript
23 +import { unstable_useMemoCache as useMemoCache } from "react";
24 +const { getNumber, identity } = require("shared-runtime");
25 +
26 +function Component(props) {
27 + const $ = useMemoCache(6);
28 + let t0;
29 + if ($[0] === Symbol.for("react.memo_cache_sentinel")) {
30 + t0 = getNumber();
31 + $[0] = t0;
32 + } else {
33 + t0 = $[0];
34 + }
35 + let t1;
36 + if ($[1] !== props.id) {
37 + t1 = identity(props.id);
38 + $[1] = props.id;
39 + $[2] = t1;
40 + } else {
41 + t1 = $[2];
42 + }
43 + let t2;
44 + if ($[3] === Symbol.for("react.memo_cache_sentinel")) {
45 + t2 = ["static"];
46 + $[3] = t2;
47 + } else {
48 + t2 = $[3];
49 + }
50 + let t3;
51 + if ($[4] !== t1) {
52 + t3 = { a: t0, b: t1, c: t2 };
53 + $[4] = t1;
54 + $[5] = t3;
55 + } else {
56 + t3 = $[5];
57 + }
58 + return t3;
59 +}
60 +
61 +export const FIXTURE_ENTRYPOINT = {
62 + fn: Component,
63 + params: [{ id: 42 }],
64 +};
65 +
66 +```
67 +
\ No newline at end of file
compiler/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/mege-consecutive-scopes-dont-merge-with-different-deps.js new
+12
@@ -0,0 +1,12 @@
1 +const { getNumber, identity } = require("shared-runtime");
2 +
3 +function Component(props) {
4 + // Two scopes: one for `getNumber()`, one for the object literal.
5 + // Neither has dependencies so they should merge
6 + return { a: getNumber(), b: identity(props.id), c: ["static"] };
7 +}
8 +
9 +export const FIXTURE_ENTRYPOINT = {
10 + fn: Component,
11 + params: [{ id: 42 }],
12 +};
compiler/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/merge-consecutive-nested-scopes.expect.md new
+52
@@ -0,0 +1,52 @@
1 +
2 +## Input
3 +
4 +```javascript
5 +const { getNumber } = require("shared-runtime");
6 +
7 +function Component(props) {
8 + let x;
9 + // Two scopes: one for `getNumber()`, one for the object literal.
10 + // Neither has dependencies so they should merge
11 + if (props.cond) {
12 + x = { session_id: getNumber() };
13 + }
14 + return x;
15 +}
16 +
17 +export const FIXTURE_ENTRYPOINT = {
18 + fn: Component,
19 + params: [{ cond: true }],
20 +};
21 +
22 +```
23 +
24 +## Code
25 +
26 +```javascript
27 +import { unstable_useMemoCache as useMemoCache } from "react";
28 +const { getNumber } = require("shared-runtime");
29 +
30 +function Component(props) {
31 + const $ = useMemoCache(1);
32 + let x;
33 + if (props.cond) {
34 + let t0;
35 + if ($[0] === Symbol.for("react.memo_cache_sentinel")) {
36 + t0 = { session_id: getNumber() };
37 + $[0] = t0;
38 + } else {
39 + t0 = $[0];
40 + }
41 + x = t0;
42 + }
43 + return x;
44 +}
45 +
46 +export const FIXTURE_ENTRYPOINT = {
47 + fn: Component,
48 + params: [{ cond: true }],
49 +};
50 +
51 +```
52 +
\ No newline at end of file
compiler/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/merge-consecutive-nested-scopes.js new
+16
@@ -0,0 +1,16 @@
1 +const { getNumber } = require("shared-runtime");
2 +
3 +function Component(props) {
4 + let x;
5 + // Two scopes: one for `getNumber()`, one for the object literal.
6 + // Neither has dependencies so they should merge
7 + if (props.cond) {
8 + x = { session_id: getNumber() };
9 + }
10 + return x;
11 +}
12 +
13 +export const FIXTURE_ENTRYPOINT = {
14 + fn: Component,
15 + params: [{ cond: true }],
16 +};