-
Notifications
You must be signed in to change notification settings - Fork 47.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
4742d27
commit 2927792
Showing
4 changed files
with
147 additions
and
0 deletions.
There are no files selected for viewing
67 changes: 67 additions & 0 deletions
67
...tures/compiler/mege-consecutive-scopes-dont-merge-with-different-deps.expect.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 }], | ||
}; | ||
|
||
``` | ||
12 changes: 12 additions & 0 deletions
12
...src/__tests__/fixtures/compiler/mege-consecutive-scopes-dont-merge-with-different-deps.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 }], | ||
}; |
52 changes: 52 additions & 0 deletions
52
...orget/src/__tests__/fixtures/compiler/merge-consecutive-nested-scopes.expect.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 }], | ||
}; | ||
|
||
``` | ||
16 changes: 16 additions & 0 deletions
16
...el-plugin-react-forget/src/__tests__/fixtures/compiler/merge-consecutive-nested-scopes.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 }], | ||
}; |