mirror of
https://github.com/facebook/react.git
synced 2025-11-01 09:12:30 +00:00
More tests for noAlias
Adds another test for `noAlias` to show that if part of the receiver could escape that we still memoize it.
This commit is contained in:
+50
@@ -0,0 +1,50 @@
|
||||
|
||||
## Input
|
||||
|
||||
```javascript
|
||||
// @enableNoAliasOptimizations
|
||||
function Component(props) {
|
||||
// This item is part of the receiver, should be memoized
|
||||
const item = { a: props.a };
|
||||
const items = [item];
|
||||
const mapped = items.map((item) => item);
|
||||
return mapped;
|
||||
}
|
||||
|
||||
export const FIXTURE_ENTRYPOINT = {
|
||||
fn: Component,
|
||||
params: [{ a: { id: 42 } }],
|
||||
isComponent: false,
|
||||
};
|
||||
|
||||
```
|
||||
|
||||
## Code
|
||||
|
||||
```javascript
|
||||
import { unstable_useMemoCache as useMemoCache } from "react"; // @enableNoAliasOptimizations
|
||||
function Component(props) {
|
||||
const $ = useMemoCache(2);
|
||||
const c_0 = $[0] !== props.a;
|
||||
let t0;
|
||||
if (c_0) {
|
||||
const item = { a: props.a };
|
||||
const items = [item];
|
||||
t0 = items.map((item_0) => item_0);
|
||||
$[0] = props.a;
|
||||
$[1] = t0;
|
||||
} else {
|
||||
t0 = $[1];
|
||||
}
|
||||
const mapped = t0;
|
||||
return mapped;
|
||||
}
|
||||
|
||||
export const FIXTURE_ENTRYPOINT = {
|
||||
fn: Component,
|
||||
params: [{ a: { id: 42 } }],
|
||||
isComponent: false,
|
||||
};
|
||||
|
||||
```
|
||||
|
||||
+14
@@ -0,0 +1,14 @@
|
||||
// @enableNoAliasOptimizations
|
||||
function Component(props) {
|
||||
// This item is part of the receiver, should be memoized
|
||||
const item = { a: props.a };
|
||||
const items = [item];
|
||||
const mapped = items.map((item) => item);
|
||||
return mapped;
|
||||
}
|
||||
|
||||
export const FIXTURE_ENTRYPOINT = {
|
||||
fn: Component,
|
||||
params: [{ a: { id: 42 } }],
|
||||
isComponent: false,
|
||||
};
|
||||
+2
-1
@@ -2,6 +2,7 @@
|
||||
## Input
|
||||
|
||||
```javascript
|
||||
// @enableNoAliasOptimizations
|
||||
function Component(props) {
|
||||
const f = (item) => item;
|
||||
const x = [...props.items].map(f); // `f` doesn't escape here...
|
||||
@@ -19,7 +20,7 @@ export const FIXTURE_ENTRYPOINT = {
|
||||
## Code
|
||||
|
||||
```javascript
|
||||
import { unstable_useMemoCache as useMemoCache } from "react";
|
||||
import { unstable_useMemoCache as useMemoCache } from "react"; // @enableNoAliasOptimizations
|
||||
function Component(props) {
|
||||
const $ = useMemoCache(5);
|
||||
let t0;
|
||||
|
||||
+1
@@ -1,3 +1,4 @@
|
||||
// @enableNoAliasOptimizations
|
||||
function Component(props) {
|
||||
const f = (item) => item;
|
||||
const x = [...props.items].map(f); // `f` doesn't escape here...
|
||||
|
||||
Reference in New Issue
Block a user