mirror of
https://github.com/facebook/react.git
synced 2025-11-01 09:12:30 +00:00
[patch] PruneHoistedContexts should traverse lambdas
This commit is contained in:
+7
-1
@@ -6,7 +6,12 @@
|
||||
*/
|
||||
|
||||
import * as t from "@babel/types";
|
||||
import { pruneUnusedLValues, pruneUnusedLabels, renameVariables } from ".";
|
||||
import {
|
||||
pruneHoistedContexts,
|
||||
pruneUnusedLValues,
|
||||
pruneUnusedLabels,
|
||||
renameVariables,
|
||||
} from ".";
|
||||
import { CompilerError, ErrorSeverity } from "../CompilerError";
|
||||
import { Environment, EnvironmentConfig, ExternalFunction } from "../HIR";
|
||||
import {
|
||||
@@ -1514,6 +1519,7 @@ function codegenInstructionValue(
|
||||
pruneUnusedLabels(reactiveFunction);
|
||||
pruneUnusedLValues(reactiveFunction);
|
||||
renameVariables(reactiveFunction);
|
||||
pruneHoistedContexts(reactiveFunction);
|
||||
const fn = codegenReactiveFunction(reactiveFunction, cx).unwrap();
|
||||
if (instrValue.expr.type === "ArrowFunctionExpression") {
|
||||
let body: t.BlockStatement | t.Expression = fn.body;
|
||||
|
||||
+60
@@ -0,0 +1,60 @@
|
||||
|
||||
## Input
|
||||
|
||||
```javascript
|
||||
function Component({}) {
|
||||
const outer = () => {
|
||||
const inner = () => {
|
||||
return x;
|
||||
};
|
||||
const x = 3;
|
||||
return inner();
|
||||
};
|
||||
return <div>{outer()}</div>;
|
||||
}
|
||||
|
||||
export const FIXTURE_ENTRYPOINT = {
|
||||
fn: Component,
|
||||
params: [{}],
|
||||
};
|
||||
|
||||
```
|
||||
|
||||
## Code
|
||||
|
||||
```javascript
|
||||
import { unstable_useMemoCache as useMemoCache } from "react";
|
||||
function Component(t22) {
|
||||
const $ = useMemoCache(2);
|
||||
let t0;
|
||||
if ($[0] === Symbol.for("react.memo_cache_sentinel")) {
|
||||
t0 = () => {
|
||||
const inner = () => x;
|
||||
|
||||
const x = 3;
|
||||
return inner();
|
||||
};
|
||||
$[0] = t0;
|
||||
} else {
|
||||
t0 = $[0];
|
||||
}
|
||||
const outer = t0;
|
||||
let t1;
|
||||
if ($[1] === Symbol.for("react.memo_cache_sentinel")) {
|
||||
t1 = <div>{outer()}</div>;
|
||||
$[1] = t1;
|
||||
} else {
|
||||
t1 = $[1];
|
||||
}
|
||||
return t1;
|
||||
}
|
||||
|
||||
export const FIXTURE_ENTRYPOINT = {
|
||||
fn: Component,
|
||||
params: [{}],
|
||||
};
|
||||
|
||||
```
|
||||
|
||||
### Eval output
|
||||
(kind: ok) <div>3</div>
|
||||
+15
@@ -0,0 +1,15 @@
|
||||
function Component({}) {
|
||||
const outer = () => {
|
||||
const inner = () => {
|
||||
return x;
|
||||
};
|
||||
const x = 3;
|
||||
return inner();
|
||||
};
|
||||
return <div>{outer()}</div>;
|
||||
}
|
||||
|
||||
export const FIXTURE_ENTRYPOINT = {
|
||||
fn: Component,
|
||||
params: [{}],
|
||||
};
|
||||
Reference in New Issue
Block a user