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:
Joe Savona
2023-09-18 14:25:12 -07:00
parent b02f5a5e0e
commit 0810175bba
4 changed files with 67 additions and 1 deletions
@@ -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,
};
```
@@ -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,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,3 +1,4 @@
// @enableNoAliasOptimizations
function Component(props) {
const f = (item) => item;
const x = [...props.items].map(f); // `f` doesn't escape here...