[tests] Repros for bugs and todos

This commit is contained in:
Mofei Zhang
2023-09-21 22:38:40 -04:00
parent b9275f65bc
commit 7b58600fb9
15 changed files with 341 additions and 0 deletions
@@ -0,0 +1,30 @@
## Input
```javascript
import { invoke } from "shared-runtime";
function Foo() {
const x = [{ value: 0 }, { value: 1 }, { value: 2 }];
const foo = (param: number) => {
return x[param].value;
};
return invoke(foo, 1);
}
export const FIXTURE_ENTRYPONT = {
fn: Foo,
params: [{}],
};
```
## Error
```
[ReactForget] Todo: EnterSSA: Expected identifier to be defined before being used. Identifier param$10 is undefined (5:5)
```
@@ -0,0 +1,15 @@
import { invoke } from "shared-runtime";
function Foo() {
const x = [{ value: 0 }, { value: 1 }, { value: 2 }];
const foo = (param: number) => {
return x[param].value;
};
return invoke(foo, 1);
}
export const FIXTURE_ENTRYPONT = {
fn: Foo,
params: [{}],
};
@@ -0,0 +1,27 @@
## Input
```javascript
import { RenderPropAsChild, StaticText1, StaticText2 } from "shared-runtime";
function Component(props: { showText1: boolean }) {
const Foo = props.showText1 ? StaticText1 : StaticText2;
return <RenderPropAsChild items={[() => <Foo />]} />;
}
export const FIXTURE_ENTRYPOINT = {
fn: Component,
params: [{ showText1: false }],
};
```
## Error
```
[ReactForget] Invariant: Expected value for identifier `28` to be initialized. (6:6)
```
@@ -0,0 +1,12 @@
import { RenderPropAsChild, StaticText1, StaticText2 } from "shared-runtime";
function Component(props: { showText1: boolean }) {
const Foo = props.showText1 ? StaticText1 : StaticText2;
return <RenderPropAsChild items={[() => <Foo />]} />;
}
export const FIXTURE_ENTRYPOINT = {
fn: Component,
params: [{ showText1: false }],
};
@@ -0,0 +1,33 @@
## Input
```javascript
function useFoo(setOne: boolean) {
let x;
let y;
let z;
if (setOne) {
x = y = z = 1;
} else {
x = 2;
y = 3;
z = 5;
}
return { x, y, z };
}
export const FIXTURE_ENTRYPONT = {
fn: useFoo,
params: [true],
};
```
## Error
```
[ReactForget] Invariant: Const declaration cannot be referenced as an expression (6:6)
```
@@ -0,0 +1,18 @@
function useFoo(setOne: boolean) {
let x;
let y;
let z;
if (setOne) {
x = y = z = 1;
} else {
x = 2;
y = 3;
z = 5;
}
return { x, y, z };
}
export const FIXTURE_ENTRYPONT = {
fn: useFoo,
params: [true],
};
@@ -0,0 +1,41 @@
## Input
```javascript
function useFoo(props: {
x?: string;
y?: string;
z?: string;
doDestructure: boolean;
}) {
let x = null;
let y = null;
let z = null;
const myList = [];
if (props.doDestructure) {
({ x, y, z } = props);
myList.push(z);
}
return {
x,
y,
myList,
};
}
export const FIXTURE_ENTRYPONT = {
fn: useFoo,
params: [{ x: "hello", y: "world", doDestructure: true }],
};
```
## Error
```
[ReactForget] Invariant: Expected consistent kind for destructuring. Other places were 'Reassign' but 'store z$44' is const (12:12)
```
@@ -0,0 +1,26 @@
function useFoo(props: {
x?: string;
y?: string;
z?: string;
doDestructure: boolean;
}) {
let x = null;
let y = null;
let z = null;
const myList = [];
if (props.doDestructure) {
({ x, y, z } = props);
myList.push(z);
}
return {
x,
y,
myList,
};
}
export const FIXTURE_ENTRYPONT = {
fn: useFoo,
params: [{ x: "hello", y: "world", doDestructure: true }],
};
@@ -0,0 +1,26 @@
## Input
```javascript
import { getNumber } from "shared-runtime";
function useFoo() {
try {
return getNumber();
} catch {}
}
export const FIXTURE_ENTRYPONT = {
fn: useFoo,
params: [],
};
```
## Error
```
[ReactForget] Invariant: Cannot emit the same block twice: bb2
```
@@ -0,0 +1,11 @@
import { getNumber } from "shared-runtime";
function useFoo() {
try {
return getNumber();
} catch {}
}
export const FIXTURE_ENTRYPONT = {
fn: useFoo,
params: [],
};
@@ -0,0 +1,26 @@
## Input
```javascript
import { useNoAlias } from "shared-runtime";
function useFoo(props: { value: { x: string; y: string } | null }) {
const value = props.value;
return useNoAlias(value?.x, value?.y) ?? {};
}
export const FIXTURE_ENTRYPONT = {
fn: useFoo,
props: [{ value: null }],
};
```
## Error
```
[ReactForget] Invariant: Unexpected terminal kind 'optional' for logical test block (5:5)
```
@@ -0,0 +1,11 @@
import { useNoAlias } from "shared-runtime";
function useFoo(props: { value: { x: string; y: string } | null }) {
const value = props.value;
return useNoAlias(value?.x, value?.y) ?? {};
}
export const FIXTURE_ENTRYPONT = {
fn: useFoo,
props: [{ value: null }],
};
@@ -0,0 +1,31 @@
## Input
```javascript
function Foo({ value }: { value: number }) {
const factorial = (x: number) => {
if (x <= 1) {
return 1;
} else {
return x * factorial(x - 1);
}
};
return factorial(value);
}
export const FIXTURE_ENTRYPONT = {
fn: Foo,
params: [{ value: 3 }],
};
```
## Error
```
[ReactForget] Todo: EnterSSA: Expected identifier to be defined before being used. Identifier factorial$3 is undefined (2:8)
```
@@ -0,0 +1,16 @@
function Foo({ value }: { value: number }) {
const factorial = (x: number) => {
if (x <= 1) {
return 1;
} else {
return x * factorial(x - 1);
}
};
return factorial(value);
}
export const FIXTURE_ENTRYPONT = {
fn: Foo,
params: [{ value: 3 }],
};
@@ -86,6 +86,13 @@ export function useNoAlias(...args: Array<any>): object {
return noAliasObject;
}
export function invoke<T extends Array<any>, ReturnType>(
fn: (...input: T) => ReturnType,
...params: T
) {
return fn(...params);
}
/**
* React Components
*/
@@ -104,6 +111,17 @@ export function StaticText2(props: { children?: Array<React.ReactNode> }) {
return React.createElement("div", null, "StaticText2", props.children);
}
export function RenderPropAsChild(props: {
items: Array<() => React.ReactNode>;
}) {
return React.createElement(
"div",
null,
"HigherOrderComponent",
props.items.map((item) => item())
);
}
export function Stringify(props: any) {
return toJSON(props);
}