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

[test] Add failing test for constant propogation of globals as phi operands

Sathya Gunasekaran committed Aug 16, 2023 at 15:39 UTC c7210bac9323c4ec36b2538c3afc20922cc80057
2 files changed +39
compiler/forget/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/constant-propagate-global-phis.expect.md new
+33
@@ -0,0 +1,33 @@
1 +
2 +## Input
3 +
4 +```javascript
5 +function Test() {
6 + const { tab } = useFoo();
7 + const currentTab = tab === WAT ? WAT : BAR;
8 +
9 + return <Foo value={currentTab} />;
10 +}
11 +
12 +```
13 +
14 +## Code
15 +
16 +```javascript
17 +import { unstable_useMemoCache as useMemoCache } from "react";
18 +function Test() {
19 + const $ = useMemoCache(1);
20 + const { tab } = useFoo();
21 + tab === WAT ? WAT : BAR;
22 + let t0;
23 + if ($[0] === Symbol.for("react.memo_cache_sentinel")) {
24 + t0 = <Foo value={WAT} />;
25 + $[0] = t0;
26 + } else {
27 + t0 = $[0];
28 + }
29 + return t0;
30 +}
31 +
32 +```
33 +
\ No newline at end of file
compiler/forget/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/constant-propagate-global-phis.js new
+6
@@ -0,0 +1,6 @@
1 +function Test() {
2 + const { tab } = useFoo();
3 + const currentTab = tab === WAT ? WAT : BAR;
4 +
5 + return <Foo value={currentTab} />;
6 +}