-
Notifications
You must be signed in to change notification settings - Fork 46.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[compiler][be] Patch test fixtures for evaluator
Add more `FIXTURE_ENTRYPOINT`s '
- Loading branch information
Showing
7 changed files
with
200 additions
and
41 deletions.
There are no files selected for viewing
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
20 changes: 16 additions & 4 deletions
20
...in-react-compiler/src/__tests__/fixtures/compiler/capturing-func-alias-captured-mutate.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 |
---|---|---|
@@ -1,12 +1,24 @@ | ||
function component(foo, bar) { | ||
import {mutate} from 'shared-runtime'; | ||
|
||
function Component({foo, bar}) { | ||
let x = {foo}; | ||
let y = {bar}; | ||
const f0 = function () { | ||
let a = {y}; | ||
let a = [y]; | ||
let b = x; | ||
a.x = b; | ||
// this writes y.x = x | ||
a[0].x = b; | ||
}; | ||
f0(); | ||
mutate(y); | ||
mutate(y.x); | ||
return y; | ||
} | ||
|
||
export const FIXTURE_ENTRYPOINT = { | ||
fn: Component, | ||
params: [{foo: 3, bar: 4}], | ||
sequentialRenders: [ | ||
{foo: 3, bar: 4}, | ||
{foo: 3, bar: 5}, | ||
], | ||
}; |
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
21 changes: 14 additions & 7 deletions
21
...ages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/capturing-func-mutate.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 |
---|---|---|
@@ -1,16 +1,23 @@ | ||
function component(a, b) { | ||
import {mutate} from 'shared-runtime'; | ||
|
||
function Component({a, b}) { | ||
let z = {a}; | ||
let y = {b}; | ||
let y = {b: {b}}; | ||
let x = function () { | ||
z.a = 2; | ||
console.log(y.b); | ||
mutate(y.b); | ||
}; | ||
x(); | ||
return z; | ||
return [y, z]; | ||
} | ||
|
||
export const FIXTURE_ENTRYPOINT = { | ||
fn: component, | ||
params: ['TodoAdd'], | ||
isComponent: 'TodoAdd', | ||
fn: Component, | ||
params: [{a: 2, b: 3}], | ||
sequentialRenders: [ | ||
{a: 2, b: 3}, | ||
{a: 2, b: 3}, | ||
{a: 4, b: 3}, | ||
{a: 4, b: 5}, | ||
], | ||
}; |
72 changes: 72 additions & 0 deletions
72
...act-compiler/src/__tests__/fixtures/compiler/capturing-func-no-mutate.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,72 @@ | ||
|
||
## Input | ||
|
||
```javascript | ||
function Component({a, b}) { | ||
let z = {a}; | ||
let y = {b}; | ||
let x = function () { | ||
z.a = 2; | ||
return Math.max(y.b, 0); | ||
}; | ||
x(); | ||
return z; | ||
} | ||
|
||
export const FIXTURE_ENTRYPOINT = { | ||
fn: Component, | ||
params: [{a: 2, b: 3}], | ||
sequentialRenders: [ | ||
{a: 2, b: 3}, | ||
{a: 2, b: 3}, | ||
{a: 4, b: 3}, | ||
{a: 4, b: 5}, | ||
], | ||
}; | ||
|
||
``` | ||
|
||
## Code | ||
|
||
```javascript | ||
import { c as _c } from "react/compiler-runtime"; | ||
function Component(t0) { | ||
const $ = _c(3); | ||
const { a, b } = t0; | ||
let z; | ||
if ($[0] !== a || $[1] !== b) { | ||
z = { a }; | ||
const y = { b }; | ||
const x = function () { | ||
z.a = 2; | ||
return Math.max(y.b, 0); | ||
}; | ||
|
||
x(); | ||
$[0] = a; | ||
$[1] = b; | ||
$[2] = z; | ||
} else { | ||
z = $[2]; | ||
} | ||
return z; | ||
} | ||
|
||
export const FIXTURE_ENTRYPOINT = { | ||
fn: Component, | ||
params: [{ a: 2, b: 3 }], | ||
sequentialRenders: [ | ||
{ a: 2, b: 3 }, | ||
{ a: 2, b: 3 }, | ||
{ a: 4, b: 3 }, | ||
{ a: 4, b: 5 }, | ||
], | ||
}; | ||
|
||
``` | ||
### Eval output | ||
(kind: ok) {"a":2} | ||
{"a":2} | ||
{"a":2} | ||
{"a":2} |
21 changes: 21 additions & 0 deletions
21
...s/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/capturing-func-no-mutate.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,21 @@ | ||
function Component({a, b}) { | ||
let z = {a}; | ||
let y = {b}; | ||
let x = function () { | ||
z.a = 2; | ||
return Math.max(y.b, 0); | ||
}; | ||
x(); | ||
return z; | ||
} | ||
|
||
export const FIXTURE_ENTRYPOINT = { | ||
fn: Component, | ||
params: [{a: 2, b: 3}], | ||
sequentialRenders: [ | ||
{a: 2, b: 3}, | ||
{a: 2, b: 3}, | ||
{a: 4, b: 3}, | ||
{a: 4, b: 5}, | ||
], | ||
}; |
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