Skip to content

Commit

Permalink
[compiler][be] Patch test fixtures for evaluator
Browse files Browse the repository at this point in the history
Add more `FIXTURE_ENTRYPOINT`s

'
  • Loading branch information
mofeiZ committed Oct 24, 2024
1 parent 857947f commit ded2bf2
Show file tree
Hide file tree
Showing 7 changed files with 200 additions and 41 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,39 +2,55 @@
## Input

```javascript
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},
],
};

```

## Code

```javascript
import { c as _c } from "react/compiler-runtime";
function component(foo, bar) {
import { mutate } from "shared-runtime";

function Component(t0) {
const $ = _c(3);
const { foo, bar } = t0;
let y;
if ($[0] !== foo || $[1] !== bar) {
const x = { foo };
y = { bar };
const f0 = function () {
const a = { y };
const a = [y];
const b = x;
a.x = b;

a[0].x = b;
};

f0();
mutate(y);
mutate(y.x);
$[0] = foo;
$[1] = bar;
$[2] = y;
Expand All @@ -44,5 +60,17 @@ function component(foo, bar) {
return y;
}

export const FIXTURE_ENTRYPOINT = {
fn: Component,
params: [{ foo: 3, bar: 4 }],
sequentialRenders: [
{ foo: 3, bar: 4 },
{ foo: 3, bar: 5 },
],
};

```
### Eval output
(kind: ok) {"bar":4,"x":{"foo":3,"wat0":"joe"}}
{"bar":5,"x":{"foo":3,"wat0":"joe"}}
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},
],
};
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,28 @@
## Input

```javascript
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},
],
};

```
Expand All @@ -25,32 +32,46 @@ export const FIXTURE_ENTRYPOINT = {

```javascript
import { c as _c } from "react/compiler-runtime";
function component(a, b) {
import { mutate } from "shared-runtime";

function Component(t0) {
const $ = _c(3);
let z;
const { a, b } = t0;
let t1;
if ($[0] !== a || $[1] !== b) {
z = { a };
const y = { b };
const z = { a };
const y = { b: { b } };
const x = function () {
z.a = 2;
console.log(y.b);
mutate(y.b);
};

x();
t1 = [y, z];
$[0] = a;
$[1] = b;
$[2] = z;
$[2] = t1;
} else {
z = $[2];
t1 = $[2];
}
return z;
return t1;
}

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 },
],
};

```
### Eval output
(kind: ok) [{"b":{"b":3,"wat0":"joe"}},{"a":2}]
[{"b":{"b":3,"wat0":"joe"}},{"a":2}]
[{"b":{"b":3,"wat0":"joe"}},{"a":2}]
[{"b":{"b":5,"wat0":"joe"}},{"a":2}]
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},
],
};
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}
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},
],
};
2 changes: 0 additions & 2 deletions compiler/packages/snap/src/SproutTodoFilter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ const skipFilter = new Set([
'capturing-arrow-function-1',
'capturing-func-mutate-3',
'capturing-func-mutate-nested',
'capturing-func-mutate',
'capturing-function-1',
'capturing-function-alias-computed-load',
'capturing-function-decl',
Expand Down Expand Up @@ -236,7 +235,6 @@ const skipFilter = new Set([
'capturing-fun-alias-captured-mutate-2',
'capturing-fun-alias-captured-mutate-arr-2',
'capturing-func-alias-captured-mutate-arr',
'capturing-func-alias-captured-mutate',
'capturing-func-alias-computed-mutate',
'capturing-func-alias-mutate',
'capturing-func-alias-receiver-computed-mutate',
Expand Down

0 comments on commit ded2bf2

Please sign in to comment.