mirror of
https://github.com/facebook/react.git
synced 2025-11-01 09:12:30 +00:00
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.
This commit is contained in:
@@ -210,6 +210,13 @@ function* runWithEnvironment(
|
||||
value: reactiveFunction,
|
||||
});
|
||||
|
||||
pruneUnusedLabels(reactiveFunction);
|
||||
yield log({
|
||||
kind: "reactive",
|
||||
name: "PruneUnusedLabels",
|
||||
value: reactiveFunction,
|
||||
});
|
||||
|
||||
memoizeFbtOperandsInSameScope(reactiveFunction);
|
||||
yield log({
|
||||
kind: "reactive",
|
||||
@@ -320,13 +327,6 @@ function* runWithEnvironment(
|
||||
value: reactiveFunction,
|
||||
});
|
||||
|
||||
pruneUnusedLabels(reactiveFunction);
|
||||
yield log({
|
||||
kind: "reactive",
|
||||
name: "PruneUnusedLabels",
|
||||
value: reactiveFunction,
|
||||
});
|
||||
|
||||
pruneUnusedLValues(reactiveFunction);
|
||||
yield log({
|
||||
kind: "reactive",
|
||||
|
||||
+49
@@ -0,0 +1,49 @@
|
||||
|
||||
## Input
|
||||
|
||||
```javascript
|
||||
function Component(props) {
|
||||
const items = (() => {
|
||||
return foo() ?? [];
|
||||
})();
|
||||
items.push(props.a);
|
||||
return items;
|
||||
}
|
||||
|
||||
export const FIXTURE_ENTRYPOINT = {
|
||||
fn: Component,
|
||||
params: [{ a: {} }],
|
||||
};
|
||||
|
||||
```
|
||||
|
||||
## Code
|
||||
|
||||
```javascript
|
||||
import { unstable_useMemoCache as useMemoCache } from "react";
|
||||
function Component(props) {
|
||||
const $ = useMemoCache(3);
|
||||
let t10;
|
||||
let items;
|
||||
if ($[0] !== props.a) {
|
||||
t10 = foo() ?? [];
|
||||
items = t10;
|
||||
|
||||
items.push(props.a);
|
||||
$[0] = props.a;
|
||||
$[1] = items;
|
||||
$[2] = t10;
|
||||
} else {
|
||||
items = $[1];
|
||||
t10 = $[2];
|
||||
}
|
||||
return items;
|
||||
}
|
||||
|
||||
export const FIXTURE_ENTRYPOINT = {
|
||||
fn: Component,
|
||||
params: [{ a: {} }],
|
||||
};
|
||||
|
||||
```
|
||||
|
||||
+12
@@ -0,0 +1,12 @@
|
||||
function Component(props) {
|
||||
const items = (() => {
|
||||
return foo() ?? [];
|
||||
})();
|
||||
items.push(props.a);
|
||||
return items;
|
||||
}
|
||||
|
||||
export const FIXTURE_ENTRYPOINT = {
|
||||
fn: Component,
|
||||
params: [{ a: {} }],
|
||||
};
|
||||
Reference in New Issue
Block a user