Skip to content

Commit

Permalink
Extra tests for #2339
Browse files Browse the repository at this point in the history
  • Loading branch information
josephsavona committed Nov 10, 2023
1 parent 4742d27 commit 2927792
Show file tree
Hide file tree
Showing 4 changed files with 147 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@

## Input

```javascript
const { getNumber, identity } = require("shared-runtime");

function Component(props) {
// Two scopes: one for `getNumber()`, one for the object literal.
// Neither has dependencies so they should merge
return { a: getNumber(), b: identity(props.id), c: ["static"] };
}

export const FIXTURE_ENTRYPOINT = {
fn: Component,
params: [{ id: 42 }],
};

```

## Code

```javascript
import { unstable_useMemoCache as useMemoCache } from "react";
const { getNumber, identity } = require("shared-runtime");

function Component(props) {
const $ = useMemoCache(6);
let t0;
if ($[0] === Symbol.for("react.memo_cache_sentinel")) {
t0 = getNumber();
$[0] = t0;
} else {
t0 = $[0];
}
let t1;
if ($[1] !== props.id) {
t1 = identity(props.id);
$[1] = props.id;
$[2] = t1;
} else {
t1 = $[2];
}
let t2;
if ($[3] === Symbol.for("react.memo_cache_sentinel")) {
t2 = ["static"];
$[3] = t2;
} else {
t2 = $[3];
}
let t3;
if ($[4] !== t1) {
t3 = { a: t0, b: t1, c: t2 };
$[4] = t1;
$[5] = t3;
} else {
t3 = $[5];
}
return t3;
}

export const FIXTURE_ENTRYPOINT = {
fn: Component,
params: [{ id: 42 }],
};

```
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
const { getNumber, identity } = require("shared-runtime");

function Component(props) {
// Two scopes: one for `getNumber()`, one for the object literal.
// Neither has dependencies so they should merge
return { a: getNumber(), b: identity(props.id), c: ["static"] };
}

export const FIXTURE_ENTRYPOINT = {
fn: Component,
params: [{ id: 42 }],
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@

## Input

```javascript
const { getNumber } = require("shared-runtime");

function Component(props) {
let x;
// Two scopes: one for `getNumber()`, one for the object literal.
// Neither has dependencies so they should merge
if (props.cond) {
x = { session_id: getNumber() };
}
return x;
}

export const FIXTURE_ENTRYPOINT = {
fn: Component,
params: [{ cond: true }],
};

```

## Code

```javascript
import { unstable_useMemoCache as useMemoCache } from "react";
const { getNumber } = require("shared-runtime");

function Component(props) {
const $ = useMemoCache(1);
let x;
if (props.cond) {
let t0;
if ($[0] === Symbol.for("react.memo_cache_sentinel")) {
t0 = { session_id: getNumber() };
$[0] = t0;
} else {
t0 = $[0];
}
x = t0;
}
return x;
}

export const FIXTURE_ENTRYPOINT = {
fn: Component,
params: [{ cond: true }],
};

```
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
const { getNumber } = require("shared-runtime");

function Component(props) {
let x;
// Two scopes: one for `getNumber()`, one for the object literal.
// Neither has dependencies so they should merge
if (props.cond) {
x = { session_id: getNumber() };
}
return x;
}

export const FIXTURE_ENTRYPOINT = {
fn: Component,
params: [{ cond: true }],
};

0 comments on commit 2927792

Please sign in to comment.