Skip to content

Commit d29c78e

Browse files
committed
Add spread syntax tests for JsxExpressions
And baselines
1 parent 0faf32b commit d29c78e

File tree

7 files changed

+352
-0
lines changed

7 files changed

+352
-0
lines changed
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
//// [tsxSpreadChildren.tsx]
2+
3+
declare module JSX {
4+
interface Element { }
5+
interface IntrinsicElements {
6+
[s: string]: any;
7+
}
8+
}
9+
declare var React: any;
10+
11+
interface TodoProp {
12+
id: number;
13+
todo: string;
14+
}
15+
interface TodoListProps {
16+
todos: TodoProp[];
17+
}
18+
function Todo(prop: { key: number, todo: string }) {
19+
return <div>{prop.key.toString() + prop.todo}</div>;
20+
}
21+
function TodoList({ todos }: TodoListProps) {
22+
return <div>
23+
{...todos.map(todo => <Todo key={todo.id} todo={todo.todo}/>)}
24+
</div>;
25+
}
26+
let x: TodoListProps;
27+
<TodoList {...x}/>
28+
29+
30+
//// [tsxSpreadChildren.jsx]
31+
function Todo(prop) {
32+
return <div>{prop.key.toString() + prop.todo}</div>;
33+
}
34+
function TodoList(_a) {
35+
var todos = _a.todos;
36+
return <div>
37+
{...todos.map(function (todo) { return <Todo key={todo.id} todo={todo.todo}/>; })}
38+
</div>;
39+
}
40+
var x;
41+
<TodoList {...x}/>;
Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
=== tests/cases/conformance/jsx/tsxSpreadChildren.tsx ===
2+
3+
declare module JSX {
4+
>JSX : Symbol(JSX, Decl(tsxSpreadChildren.tsx, 0, 0))
5+
6+
interface Element { }
7+
>Element : Symbol(Element, Decl(tsxSpreadChildren.tsx, 1, 20))
8+
9+
interface IntrinsicElements {
10+
>IntrinsicElements : Symbol(IntrinsicElements, Decl(tsxSpreadChildren.tsx, 2, 22))
11+
12+
[s: string]: any;
13+
>s : Symbol(s, Decl(tsxSpreadChildren.tsx, 4, 3))
14+
}
15+
}
16+
declare var React: any;
17+
>React : Symbol(React, Decl(tsxSpreadChildren.tsx, 7, 11))
18+
19+
interface TodoProp {
20+
>TodoProp : Symbol(TodoProp, Decl(tsxSpreadChildren.tsx, 7, 23))
21+
22+
id: number;
23+
>id : Symbol(TodoProp.id, Decl(tsxSpreadChildren.tsx, 9, 20))
24+
25+
todo: string;
26+
>todo : Symbol(TodoProp.todo, Decl(tsxSpreadChildren.tsx, 10, 15))
27+
}
28+
interface TodoListProps {
29+
>TodoListProps : Symbol(TodoListProps, Decl(tsxSpreadChildren.tsx, 12, 1))
30+
31+
todos: TodoProp[];
32+
>todos : Symbol(TodoListProps.todos, Decl(tsxSpreadChildren.tsx, 13, 25))
33+
>TodoProp : Symbol(TodoProp, Decl(tsxSpreadChildren.tsx, 7, 23))
34+
}
35+
function Todo(prop: { key: number, todo: string }) {
36+
>Todo : Symbol(Todo, Decl(tsxSpreadChildren.tsx, 15, 1))
37+
>prop : Symbol(prop, Decl(tsxSpreadChildren.tsx, 16, 14))
38+
>key : Symbol(key, Decl(tsxSpreadChildren.tsx, 16, 21))
39+
>todo : Symbol(todo, Decl(tsxSpreadChildren.tsx, 16, 34))
40+
41+
return <div>{prop.key.toString() + prop.todo}</div>;
42+
>div : Symbol(JSX.IntrinsicElements, Decl(tsxSpreadChildren.tsx, 2, 22))
43+
>prop.key.toString : Symbol(Number.toString, Decl(lib.d.ts, --, --))
44+
>prop.key : Symbol(key, Decl(tsxSpreadChildren.tsx, 16, 21))
45+
>prop : Symbol(prop, Decl(tsxSpreadChildren.tsx, 16, 14))
46+
>key : Symbol(key, Decl(tsxSpreadChildren.tsx, 16, 21))
47+
>toString : Symbol(Number.toString, Decl(lib.d.ts, --, --))
48+
>prop.todo : Symbol(todo, Decl(tsxSpreadChildren.tsx, 16, 34))
49+
>prop : Symbol(prop, Decl(tsxSpreadChildren.tsx, 16, 14))
50+
>todo : Symbol(todo, Decl(tsxSpreadChildren.tsx, 16, 34))
51+
>div : Symbol(JSX.IntrinsicElements, Decl(tsxSpreadChildren.tsx, 2, 22))
52+
}
53+
function TodoList({ todos }: TodoListProps) {
54+
>TodoList : Symbol(TodoList, Decl(tsxSpreadChildren.tsx, 18, 1))
55+
>todos : Symbol(todos, Decl(tsxSpreadChildren.tsx, 19, 19))
56+
>TodoListProps : Symbol(TodoListProps, Decl(tsxSpreadChildren.tsx, 12, 1))
57+
58+
return <div>
59+
>div : Symbol(JSX.IntrinsicElements, Decl(tsxSpreadChildren.tsx, 2, 22))
60+
61+
{...todos.map(todo => <Todo key={todo.id} todo={todo.todo}/>)}
62+
>todos.map : Symbol(Array.map, Decl(lib.d.ts, --, --), Decl(lib.d.ts, --, --), Decl(lib.d.ts, --, --), Decl(lib.d.ts, --, --), Decl(lib.d.ts, --, --))
63+
>todos : Symbol(todos, Decl(tsxSpreadChildren.tsx, 19, 19))
64+
>map : Symbol(Array.map, Decl(lib.d.ts, --, --), Decl(lib.d.ts, --, --), Decl(lib.d.ts, --, --), Decl(lib.d.ts, --, --), Decl(lib.d.ts, --, --))
65+
>todo : Symbol(todo, Decl(tsxSpreadChildren.tsx, 21, 22))
66+
>Todo : Symbol(Todo, Decl(tsxSpreadChildren.tsx, 15, 1))
67+
>key : Symbol(key, Decl(tsxSpreadChildren.tsx, 16, 21))
68+
>todo.id : Symbol(TodoProp.id, Decl(tsxSpreadChildren.tsx, 9, 20))
69+
>todo : Symbol(todo, Decl(tsxSpreadChildren.tsx, 21, 22))
70+
>id : Symbol(TodoProp.id, Decl(tsxSpreadChildren.tsx, 9, 20))
71+
>todo : Symbol(todo, Decl(tsxSpreadChildren.tsx, 16, 34))
72+
>todo.todo : Symbol(TodoProp.todo, Decl(tsxSpreadChildren.tsx, 10, 15))
73+
>todo : Symbol(todo, Decl(tsxSpreadChildren.tsx, 21, 22))
74+
>todo : Symbol(TodoProp.todo, Decl(tsxSpreadChildren.tsx, 10, 15))
75+
76+
</div>;
77+
>div : Symbol(JSX.IntrinsicElements, Decl(tsxSpreadChildren.tsx, 2, 22))
78+
}
79+
let x: TodoListProps;
80+
>x : Symbol(x, Decl(tsxSpreadChildren.tsx, 24, 3))
81+
>TodoListProps : Symbol(TodoListProps, Decl(tsxSpreadChildren.tsx, 12, 1))
82+
83+
<TodoList {...x}/>
84+
>TodoList : Symbol(TodoList, Decl(tsxSpreadChildren.tsx, 18, 1))
85+
>x : Symbol(x, Decl(tsxSpreadChildren.tsx, 24, 3))
86+
Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
=== tests/cases/conformance/jsx/tsxSpreadChildren.tsx ===
2+
3+
declare module JSX {
4+
>JSX : any
5+
6+
interface Element { }
7+
>Element : Element
8+
9+
interface IntrinsicElements {
10+
>IntrinsicElements : IntrinsicElements
11+
12+
[s: string]: any;
13+
>s : string
14+
}
15+
}
16+
declare var React: any;
17+
>React : any
18+
19+
interface TodoProp {
20+
>TodoProp : TodoProp
21+
22+
id: number;
23+
>id : number
24+
25+
todo: string;
26+
>todo : string
27+
}
28+
interface TodoListProps {
29+
>TodoListProps : TodoListProps
30+
31+
todos: TodoProp[];
32+
>todos : TodoProp[]
33+
>TodoProp : TodoProp
34+
}
35+
function Todo(prop: { key: number, todo: string }) {
36+
>Todo : (prop: { key: number; todo: string; }) => JSX.Element
37+
>prop : { key: number; todo: string; }
38+
>key : number
39+
>todo : string
40+
41+
return <div>{prop.key.toString() + prop.todo}</div>;
42+
><div>{prop.key.toString() + prop.todo}</div> : JSX.Element
43+
>div : any
44+
>prop.key.toString() + prop.todo : string
45+
>prop.key.toString() : string
46+
>prop.key.toString : (radix?: number) => string
47+
>prop.key : number
48+
>prop : { key: number; todo: string; }
49+
>key : number
50+
>toString : (radix?: number) => string
51+
>prop.todo : string
52+
>prop : { key: number; todo: string; }
53+
>todo : string
54+
>div : any
55+
}
56+
function TodoList({ todos }: TodoListProps) {
57+
>TodoList : ({todos}: TodoListProps) => JSX.Element
58+
>todos : TodoProp[]
59+
>TodoListProps : TodoListProps
60+
61+
return <div>
62+
><div> {...todos.map(todo => <Todo key={todo.id} todo={todo.todo}/>)} </div> : JSX.Element
63+
>div : any
64+
65+
{...todos.map(todo => <Todo key={todo.id} todo={todo.todo}/>)}
66+
>todos.map(todo => <Todo key={todo.id} todo={todo.todo}/>) : JSX.Element[]
67+
>todos.map : { <U>(this: [TodoProp, TodoProp, TodoProp, TodoProp, TodoProp], callbackfn: (value: TodoProp, index: number, array: TodoProp[]) => U, thisArg?: any): [U, U, U, U, U]; <U>(this: [TodoProp, TodoProp, TodoProp, TodoProp], callbackfn: (value: TodoProp, index: number, array: TodoProp[]) => U, thisArg?: any): [U, U, U, U]; <U>(this: [TodoProp, TodoProp, TodoProp], callbackfn: (value: TodoProp, index: number, array: TodoProp[]) => U, thisArg?: any): [U, U, U]; <U>(this: [TodoProp, TodoProp], callbackfn: (value: TodoProp, index: number, array: TodoProp[]) => U, thisArg?: any): [U, U]; <U>(callbackfn: (value: TodoProp, index: number, array: TodoProp[]) => U, thisArg?: any): U[]; }
68+
>todos : TodoProp[]
69+
>map : { <U>(this: [TodoProp, TodoProp, TodoProp, TodoProp, TodoProp], callbackfn: (value: TodoProp, index: number, array: TodoProp[]) => U, thisArg?: any): [U, U, U, U, U]; <U>(this: [TodoProp, TodoProp, TodoProp, TodoProp], callbackfn: (value: TodoProp, index: number, array: TodoProp[]) => U, thisArg?: any): [U, U, U, U]; <U>(this: [TodoProp, TodoProp, TodoProp], callbackfn: (value: TodoProp, index: number, array: TodoProp[]) => U, thisArg?: any): [U, U, U]; <U>(this: [TodoProp, TodoProp], callbackfn: (value: TodoProp, index: number, array: TodoProp[]) => U, thisArg?: any): [U, U]; <U>(callbackfn: (value: TodoProp, index: number, array: TodoProp[]) => U, thisArg?: any): U[]; }
70+
>todo => <Todo key={todo.id} todo={todo.todo}/> : (todo: TodoProp) => JSX.Element
71+
>todo : TodoProp
72+
><Todo key={todo.id} todo={todo.todo}/> : JSX.Element
73+
>Todo : (prop: { key: number; todo: string; }) => JSX.Element
74+
>key : any
75+
>todo.id : number
76+
>todo : TodoProp
77+
>id : number
78+
>todo : any
79+
>todo.todo : string
80+
>todo : TodoProp
81+
>todo : string
82+
83+
</div>;
84+
>div : any
85+
}
86+
let x: TodoListProps;
87+
>x : TodoListProps
88+
>TodoListProps : TodoListProps
89+
90+
<TodoList {...x}/>
91+
><TodoList {...x}/> : JSX.Element
92+
>TodoList : ({todos}: TodoListProps) => JSX.Element
93+
>x : TodoListProps
94+
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
tests/cases/conformance/jsx/tsxSpreadChildrenInvalidType.tsx(21,9): error TS2609: JSX spread child must be an array type.
2+
3+
4+
==== tests/cases/conformance/jsx/tsxSpreadChildrenInvalidType.tsx (1 errors) ====
5+
declare module JSX {
6+
interface Element { }
7+
interface IntrinsicElements {
8+
[s: string]: any;
9+
}
10+
}
11+
declare var React: any;
12+
13+
interface TodoProp {
14+
id: number;
15+
todo: string;
16+
}
17+
interface TodoListProps {
18+
todos: TodoProp[];
19+
}
20+
function Todo(prop: { key: number, todo: string }) {
21+
return <div>{prop.key.toString() + prop.todo}</div>;
22+
}
23+
function TodoList({ todos }: TodoListProps) {
24+
return <div>
25+
{...<Todo key={todos[0].id} todo={todos[0].todo} />}
26+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
27+
!!! error TS2609: JSX spread child must be an array type.
28+
</div>;
29+
}
30+
let x: TodoListProps;
31+
<TodoList {...x}/>
32+
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
//// [tsxSpreadChildrenInvalidType.tsx]
2+
declare module JSX {
3+
interface Element { }
4+
interface IntrinsicElements {
5+
[s: string]: any;
6+
}
7+
}
8+
declare var React: any;
9+
10+
interface TodoProp {
11+
id: number;
12+
todo: string;
13+
}
14+
interface TodoListProps {
15+
todos: TodoProp[];
16+
}
17+
function Todo(prop: { key: number, todo: string }) {
18+
return <div>{prop.key.toString() + prop.todo}</div>;
19+
}
20+
function TodoList({ todos }: TodoListProps) {
21+
return <div>
22+
{...<Todo key={todos[0].id} todo={todos[0].todo} />}
23+
</div>;
24+
}
25+
let x: TodoListProps;
26+
<TodoList {...x}/>
27+
28+
29+
//// [tsxSpreadChildrenInvalidType.js]
30+
var __assign = (this && this.__assign) || Object.assign || function(t) {
31+
for (var s, i = 1, n = arguments.length; i < n; i++) {
32+
s = arguments[i];
33+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
34+
t[p] = s[p];
35+
}
36+
return t;
37+
};
38+
function Todo(prop) {
39+
return React.createElement("div", null, prop.key.toString() + prop.todo);
40+
}
41+
function TodoList(_a) {
42+
var todos = _a.todos;
43+
return React.createElement("div", null, React.createElement(Todo, { key: todos[0].id, todo: todos[0].todo }));
44+
}
45+
var x;
46+
React.createElement(TodoList, __assign({}, x));
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
//@jsx: preserve
2+
3+
declare module JSX {
4+
interface Element { }
5+
interface IntrinsicElements {
6+
[s: string]: any;
7+
}
8+
}
9+
declare var React: any;
10+
11+
interface TodoProp {
12+
id: number;
13+
todo: string;
14+
}
15+
interface TodoListProps {
16+
todos: TodoProp[];
17+
}
18+
function Todo(prop: { key: number, todo: string }) {
19+
return <div>{prop.key.toString() + prop.todo}</div>;
20+
}
21+
function TodoList({ todos }: TodoListProps) {
22+
return <div>
23+
{...todos.map(todo => <Todo key={todo.id} todo={todo.todo}/>)}
24+
</div>;
25+
}
26+
let x: TodoListProps;
27+
<TodoList {...x}/>
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
// @jsx: react
2+
declare module JSX {
3+
interface Element { }
4+
interface IntrinsicElements {
5+
[s: string]: any;
6+
}
7+
}
8+
declare var React: any;
9+
10+
interface TodoProp {
11+
id: number;
12+
todo: string;
13+
}
14+
interface TodoListProps {
15+
todos: TodoProp[];
16+
}
17+
function Todo(prop: { key: number, todo: string }) {
18+
return <div>{prop.key.toString() + prop.todo}</div>;
19+
}
20+
function TodoList({ todos }: TodoListProps) {
21+
return <div>
22+
{...<Todo key={todos[0].id} todo={todos[0].todo} />}
23+
</div>;
24+
}
25+
let x: TodoListProps;
26+
<TodoList {...x}/>

0 commit comments

Comments
 (0)