@samitouri / QOS-React-2 / commits / 35fee31355

Handle IIFE with logical mutated later

The previous changes mostly meant that we removed the label terminal and didn't have instructions for the same scope split in a way that we couldn't merge. But logicals were still causing a split because MergeConsecutiveScopes can't merge the blocks in that case. Here we move PruneUnusedLabels earlier in the pipeline to ensure that instructions from IIFEs have floated up to the parent block scope level.

Joe Savona committed Nov 6, 2023 at 08:33 UTC 35fee3135561ec3259cce695f4e2bb0863f7d7e0
3 files changed +68 -7
compiler/packages/babel-plugin-react-forget/src/Entrypoint/Pipeline.ts
+7 -7
@@ -210,6 +210,13 @@ function* runWithEnvironment(
210 value: reactiveFunction,
211 });
212
213 + pruneUnusedLabels(reactiveFunction);
214 + yield log({
215 + kind: "reactive",
216 + name: "PruneUnusedLabels",
217 + value: reactiveFunction,
218 + });
219 +
220 memoizeFbtOperandsInSameScope(reactiveFunction);
221 yield log({
222 kind: "reactive",
@@ -320,13 +327,6 @@ function* runWithEnvironment(
327 value: reactiveFunction,
328 });
329
323 - pruneUnusedLabels(reactiveFunction);
324 - yield log({
325 - kind: "reactive",
326 - name: "PruneUnusedLabels",
327 - value: reactiveFunction,
328 - });
329 -
330 pruneUnusedLValues(reactiveFunction);
331 yield log({
332 kind: "reactive",
compiler/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/iife-return-modified-later-logical.expect.md new
+49
@@ -0,0 +1,49 @@
1 +
2 +## Input
3 +
4 +```javascript
5 +function Component(props) {
6 + const items = (() => {
7 + return foo() ?? [];
8 + })();
9 + items.push(props.a);
10 + return items;
11 +}
12 +
13 +export const FIXTURE_ENTRYPOINT = {
14 + fn: Component,
15 + params: [{ a: {} }],
16 +};
17 +
18 +```
19 +
20 +## Code
21 +
22 +```javascript
23 +import { unstable_useMemoCache as useMemoCache } from "react";
24 +function Component(props) {
25 + const $ = useMemoCache(3);
26 + let t10;
27 + let items;
28 + if ($[0] !== props.a) {
29 + t10 = foo() ?? [];
30 + items = t10;
31 +
32 + items.push(props.a);
33 + $[0] = props.a;
34 + $[1] = items;
35 + $[2] = t10;
36 + } else {
37 + items = $[1];
38 + t10 = $[2];
39 + }
40 + return items;
41 +}
42 +
43 +export const FIXTURE_ENTRYPOINT = {
44 + fn: Component,
45 + params: [{ a: {} }],
46 +};
47 +
48 +```
49 +
\ No newline at end of file
compiler/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/iife-return-modified-later-logical.js new
+12
@@ -0,0 +1,12 @@
1 +function Component(props) {
2 + const items = (() => {
3 + return foo() ?? [];
4 + })();
5 + items.push(props.a);
6 + return items;
7 +}
8 +
9 +export const FIXTURE_ENTRYPOINT = {
10 + fn: Component,
11 + params: [{ a: {} }],
12 +};