Skip to content

Commit 48b48e1

Browse files
refactor: add tests for satisfies operator for arrays
1 parent bd0c39d commit 48b48e1

File tree

2 files changed

+86
-0
lines changed

2 files changed

+86
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
2+
## Input
3+
4+
```javascript
5+
// @enableUseTypeAnnotations
6+
function Component(props: {id: number}) {
7+
const x = makeArray(props.id) satisfies number[];
8+
const y = x.at(0);
9+
return y;
10+
}
11+
12+
function makeArray<T>(x: T): Array<T> {
13+
return [x];
14+
}
15+
16+
export const FIXTURE_ENTRYPOINT = {
17+
fn: Component,
18+
params: [{id: 42}],
19+
};
20+
21+
```
22+
23+
## Code
24+
25+
```javascript
26+
import { c as _c } from "react/compiler-runtime"; // @enableUseTypeAnnotations
27+
function Component(props) {
28+
const $ = _c(4);
29+
let t0;
30+
if ($[0] !== props.id) {
31+
t0 = makeArray(props.id);
32+
$[0] = props.id;
33+
$[1] = t0;
34+
} else {
35+
t0 = $[1];
36+
}
37+
const x = t0 satisfies number[];
38+
let t1;
39+
if ($[2] !== x) {
40+
t1 = x.at(0);
41+
$[2] = x;
42+
$[3] = t1;
43+
} else {
44+
t1 = $[3];
45+
}
46+
const y = t1;
47+
return y;
48+
}
49+
50+
function makeArray(x) {
51+
const $ = _c(2);
52+
let t0;
53+
if ($[0] !== x) {
54+
t0 = [x];
55+
$[0] = x;
56+
$[1] = t0;
57+
} else {
58+
t0 = $[1];
59+
}
60+
return t0;
61+
}
62+
63+
export const FIXTURE_ENTRYPOINT = {
64+
fn: Component,
65+
params: [{ id: 42 }],
66+
};
67+
68+
```
69+
70+
### Eval output
71+
(kind: ok) 42
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
// @enableUseTypeAnnotations
2+
function Component(props: {id: number}) {
3+
const x = makeArray(props.id) satisfies number[];
4+
const y = x.at(0);
5+
return y;
6+
}
7+
8+
function makeArray<T>(x: T): Array<T> {
9+
return [x];
10+
}
11+
12+
export const FIXTURE_ENTRYPOINT = {
13+
fn: Component,
14+
params: [{id: 42}],
15+
};

0 commit comments

Comments
 (0)