Skip to content

Commit bc9b53a

Browse files
committed
Conformance tests for JSX
1 parent 2b44dca commit bc9b53a

File tree

62 files changed

+1295
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

62 files changed

+1295
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
// @jsx: preserve
2+
3+
declare var createElement: any;
4+
5+
class foo {}
6+
7+
var x: any;
8+
x = <any> { test: <any></any> };
9+
10+
x = <any><any></any>;
11+
12+
x = <foo>hello {<foo>{}} </foo>;
13+
14+
x = <foo test={<foo>{}}>hello</foo>;
15+
16+
x = <foo test={<foo>{}}>hello{<foo>{}}</foo>;
17+
18+
x = <foo>x</foo>, x = <foo/>;
19+
20+
<foo>{<foo><foo>{/foo/.test(x) ? <foo><foo></foo> : <foo><foo></foo>}</foo>}</foo>
21+
22+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
// @jsx: preserve
2+
declare var React: any;
3+
declare var 日本語;
4+
declare var AbC_def;
5+
declare var LeftRight;
6+
declare var x;
7+
declare var a;
8+
declare var props;
9+
10+
<a />;
11+
12+
//<n:a n:v />; Namespace unsuported
13+
14+
//<a n:foo="bar"> {value} <b><c /></b></a>; Namespace unsuported
15+
16+
<a b={" "} c=" " d="&amp;" e="id=1&group=2" f="&#123456789" g="&#123*;" h="&#x;" />;
17+
18+
<a b="&notanentity;" />;
19+
<a
20+
/>;
21+
22+
<日本語></日本語>;
23+
24+
<AbC_def
25+
test="&#x0026;&#38;">
26+
bar
27+
baz
28+
</AbC_def>;
29+
30+
<a b={x ? <c /> : <d />} />;
31+
32+
<a>{}</a>;
33+
34+
<a>{/* this is a comment */}</a>;
35+
36+
<div>@test content</div>;
37+
38+
<div><br />7x invalid-js-identifier</div>;
39+
40+
<LeftRight left=<a /> right=<b>monkeys /> gorillas</b> />;
41+
42+
<a.b></a.b>;
43+
44+
<a.b.c></a.b.c>;
45+
46+
(<div />) < x;
47+
48+
<div {...props} />;
49+
50+
<div {...props} post="attribute" />;
51+
52+
<div pre="leading" pre2="attribute" {...props}></div>;
53+
54+
<a> </a>;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
// @jsx: preserve
2+
declare var React: any;
3+
4+
</>;
5+
<a: />;
6+
<:a />;
7+
<a b=d />;
8+
<a>;
9+
<a></b>;
10+
<a foo="bar;
11+
<a:b></b>;
12+
<a:b.c></a:b.c>;
13+
<a.b:c></a.b:c>;
14+
<a.b.c></a>;
15+
<.a></.a>;
16+
<a.></a.>;
17+
<a[foo]></a[foo]>;
18+
<a['foo']></a['foo']>;
19+
<a><a />;
20+
<a b={}>;
21+
var x = <div>one</div><div>two</div>;;
22+
var x = <div>one</div> /* intervening comment */ <div>two</div>;;
23+
<a>{"str";}</a>;
24+
<span className="a", id="b" />;
25+
<div className"app">;
26+
<div {props} />;
27+
28+
<div>stuff</div {...props}>;
29+
<div {...props}>stuff</div {...props}>;
30+
31+
<a>></a>;
32+
<a> ></a>;
33+
<a b=}>;
34+
<a b=<}>;
35+
<a>}</a>;
36+
<a .../*hai*/asdf/>;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,117 @@
1+
// @jsx: preserve
2+
3+
declare var React: any;
4+
declare var Component:any;
5+
declare var Composite:any;
6+
declare var Composite2:any;
7+
declare var Child:any;
8+
declare var Namespace:any;
9+
declare var foo: any;
10+
declare var bar: any;
11+
declare var y:any;
12+
declare var x:any;
13+
declare var z:any;
14+
declare var hasOwnProperty:any;
15+
16+
<div>text</div>;
17+
18+
<div>
19+
{this.props.children}
20+
</div>;
21+
22+
<div>
23+
<div><br /></div>
24+
<Component>{foo}<br />{bar}</Component>
25+
<br />
26+
</div>;
27+
28+
29+
<Composite>
30+
{this.props.children}
31+
</Composite>;
32+
33+
<Composite>
34+
<Composite2 />
35+
</Composite>;
36+
37+
var x =
38+
<div
39+
attr1={
40+
"foo" + "bar"
41+
}
42+
attr2={
43+
"foo" + "bar" +
44+
45+
"baz" + "bug"
46+
}
47+
attr3={
48+
"foo" + "bar" +
49+
"baz" + "bug"
50+
// Extra line here.
51+
}
52+
attr4="baz">
53+
</div>;
54+
55+
(
56+
<div>
57+
{/* A comment at the beginning */}
58+
{/* A second comment at the beginning */}
59+
<span>
60+
{/* A nested comment */}
61+
</span>
62+
{/* A sandwiched comment */}
63+
<br />
64+
{/* A comment at the end */}
65+
{/* A second comment at the end */}
66+
</div>
67+
);
68+
69+
(
70+
<div
71+
/* a multi-line
72+
comment */
73+
attr1="foo">
74+
<span // a double-slash comment
75+
attr2="bar"
76+
/>
77+
</div>
78+
);
79+
80+
<div>&nbsp;</div>;
81+
82+
<div>&nbsp; </div>;
83+
84+
<hasOwnProperty>testing</hasOwnProperty>;
85+
86+
<Component constructor="foo" />;
87+
88+
<Namespace.Component />;
89+
90+
<Namespace.DeepNamespace.Component />;
91+
92+
<Component { ... x } y
93+
={2 } z />;
94+
95+
<Component
96+
{...this.props} sound="moo" />;
97+
98+
<font-face />;
99+
100+
<Component x={y} />;
101+
102+
<x-component />;
103+
104+
<Component {...x} />;
105+
106+
<Component { ...x } y={2} />;
107+
108+
<Component { ... x } y={2} z />;
109+
110+
<Component x={1} {...y} />;
111+
112+
113+
<Component x={1} y="2" {...z} {...z}><Child /></Component>;
114+
115+
<Component x="1" {...(z = { y: 2 }, z)} z={3}>Text</Component>;
116+
117+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
// @jsx: preserve
2+
3+
declare namespace JSX {
4+
interface Element { }
5+
interface IntrinsicElements {
6+
div: {
7+
text?: string;
8+
width?: number;
9+
}
10+
11+
span: any;
12+
}
13+
}
14+
15+
// Error, number is not assignable to string
16+
<div text={42} />;
17+
18+
// Error, string is not assignable to number
19+
<div width={'foo'} />;
20+
21+
// Error, number is not assignable to string
22+
var attribs = { text: 100 };
23+
<div {...attribs} />;
24+
25+
// No errors here
26+
<span foo='bar' bar={'foo'} />;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
//@filename: file.tsx
2+
//@jsx: preserve
3+
declare module JSX {
4+
interface Element { }
5+
interface IntrinsicElements {
6+
test1: { "data-foo"?: string };
7+
}
8+
}
9+
10+
// Invalid names
11+
<test1 32data={32} />;
12+
<test1 -data={32} />;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
/// @jsx: preserve
2+
3+
declare namespace JSX {
4+
interface IntrinsicElements {
5+
x: { y: number; z: string; };
6+
}
7+
}
8+
9+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
// OK
2+
<test1 x={0}/>; // OK
3+
<test1 />; // OK
4+
<test1 data-x={true}/>; // OK
5+
<test2 reqd='true'/>; // OK
6+
<test2 reqd={'true'}/>; // OK
7+
// Errors
8+
<test1 x={'0'}/>; // Error, '0' is not number
9+
<test1 y={0}/>; // Error, no property "y"
10+
<test1 y="foo"/>; // Error, no property "y"
11+
<test1 x="32"/>; // Error, "32" is not number
12+
// TODO attribute 'var' should be parseable
13+
// <test1 var="10" />; // Error, no 'var' property
14+
<test2 />; // Error, missing reqd
15+
<test2 reqd={10}/>; // Error, reqd is not string
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
//@filename: file.tsx
2+
//@jsx: preserve
3+
declare module JSX {
4+
interface Element { }
5+
interface IntrinsicElements {
6+
test1: Attribs1;
7+
test2: { reqd: string };
8+
}
9+
}
10+
interface Attribs1 {
11+
x?: number;
12+
s?: string;
13+
}
14+
15+
// OK
16+
<test1 x={0} />; // OK
17+
<test1 />; // OK
18+
<test1 data-x={true} />; // OK
19+
20+
<test2 reqd='true' />; // OK
21+
<test2 reqd={'true'} />; // OK
22+
23+
// Errors
24+
<test1 x={'0'} />; // Error, '0' is not number
25+
<test1 y={0} />; // Error, no property "y"
26+
<test1 y="foo" />; // Error, no property "y"
27+
<test1 x="32" />; // Error, "32" is not number
28+
// TODO attribute 'var' should be parseable
29+
// <test1 var="10" />; // Error, no 'var' property
30+
31+
<test2 />; // Error, missing reqd
32+
<test2 reqd={10} />; // Error, reqd is not string
33+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
// OK
2+
<test1 c1={function (x) { return x.length; }}/>; // OK
3+
<test1 data-c1={function (x) { return x.leng; }}/>; // OK
4+
// Errors
5+
<test1 c1={function (x) { return x.leng; }}/>; // Error, no leng on 'string'
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
//@filename: file.tsx
2+
//@jsx: preserve
3+
declare module JSX {
4+
interface Element { }
5+
interface IntrinsicElements {
6+
test1: Attribs1;
7+
}
8+
}
9+
interface Attribs1 {
10+
c1?: (x: string) => void;
11+
}
12+
13+
// OK
14+
<test1 c1={(x) => x.length} />; // OK
15+
<test1 data-c1={(x) => x.leng} />; // OK
16+
17+
18+
// Errors
19+
<test1 c1={(x) => x.leng} />; // Error, no leng on 'string'
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
// OK
2+
var obj1 = { x: 'foo' };
3+
<test1 {...obj1}/>;
4+
// Error, x is not string
5+
var obj2 = { x: 32 };
6+
<test1 {...obj2}/>;
7+
// Error, x is missing
8+
var obj3 = { y: 32 };
9+
<test1 {...obj3}/>;
10+
// OK
11+
var obj4 = { x: 32, y: 32 };
12+
<test1 {...obj4} x="ok"/>;
13+
// Error
14+
var obj5 = { x: 32, y: 32 };
15+
<test1 x="ok" {...obj5}/>;
16+
// OK
17+
var obj6 = { x: 'ok', y: 32, extra: 100 };
18+
<test1 {...obj6}/>;
19+
// Error
20+
var obj7 = { x: 'foo' };
21+
<test1 x={32} {...obj7}/>;

0 commit comments

Comments
 (0)