Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[compiler] Fixture for function outlining #30329

Merged
merged 2 commits into from
Jul 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@

## Input

```javascript
import { Stringify } from "shared-runtime";

function Component(props) {
return (
<div>
{props.items.map((item) => (
<Stringify key={item.id} item={item.name} />
))}
</div>
);
}

export const FIXTURE_ENTRYPOINT = {
fn: Component,
params: [{ items: [{ id: 1, name: "one" }] }],
};

```

## Code

```javascript
import { c as _c } from "react/compiler-runtime";
import { Stringify } from "shared-runtime";

function Component(props) {
const $ = _c(5);
let t0;
if ($[0] !== props.items) {
let t1;
if ($[2] === Symbol.for("react.memo_cache_sentinel")) {
t1 = (item) => <Stringify key={item.id} item={item.name} />;
$[2] = t1;
} else {
t1 = $[2];
}
t0 = props.items.map(t1);
$[0] = props.items;
$[1] = t0;
} else {
t0 = $[1];
}
let t1;
if ($[3] !== t0) {
t1 = <div>{t0}</div>;
$[3] = t0;
$[4] = t1;
} else {
t1 = $[4];
}
return t1;
}

export const FIXTURE_ENTRYPOINT = {
fn: Component,
params: [{ items: [{ id: 1, name: "one" }] }],
};

```
### Eval output
(kind: ok) <div><div>{"item":"one"}</div></div>
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import { Stringify } from "shared-runtime";

function Component(props) {
return (
<div>
{props.items.map((item) => (
<Stringify key={item.id} item={item.name} />
))}
</div>
);
}

export const FIXTURE_ENTRYPOINT = {
fn: Component,
params: [{ items: [{ id: 1, name: "one" }] }],
};