Skip to content

Commit b8f8fd7

Browse files
authored
fix(46512): allow to use tag names containing keywords with - (#46546)
1 parent 33fe1b6 commit b8f8fd7

9 files changed

+216
-0
lines changed

src/compiler/scanner.ts

+1
Original file line numberDiff line numberDiff line change
@@ -2374,6 +2374,7 @@ namespace ts {
23742374
tokenValue = tokenValue.slice(0, -1);
23752375
pos--;
23762376
}
2377+
return getIdentifierToken();
23772378
}
23782379
return token;
23792380
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
//// [a.tsx]
2+
declare const React: any
3+
declare namespace JSX {
4+
interface IntrinsicElements {
5+
[k: string]: any
6+
}
7+
}
8+
9+
const a = (
10+
<public-foo></public-foo>
11+
);
12+
13+
const b = (
14+
<public></public>
15+
);
16+
17+
18+
//// [a.js]
19+
var a = (React.createElement("public-foo", null));
20+
var b = (React.createElement("public", null));
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
=== tests/cases/conformance/jsx/a.tsx ===
2+
declare const React: any
3+
>React : Symbol(React, Decl(a.tsx, 0, 13))
4+
5+
declare namespace JSX {
6+
>JSX : Symbol(JSX, Decl(a.tsx, 0, 24))
7+
8+
interface IntrinsicElements {
9+
>IntrinsicElements : Symbol(IntrinsicElements, Decl(a.tsx, 1, 23))
10+
11+
[k: string]: any
12+
>k : Symbol(k, Decl(a.tsx, 3, 9))
13+
}
14+
}
15+
16+
const a = (
17+
>a : Symbol(a, Decl(a.tsx, 7, 5))
18+
19+
<public-foo></public-foo>
20+
>public-foo : Symbol(JSX.IntrinsicElements, Decl(a.tsx, 1, 23))
21+
>public-foo : Symbol(JSX.IntrinsicElements, Decl(a.tsx, 1, 23))
22+
23+
);
24+
25+
const b = (
26+
>b : Symbol(b, Decl(a.tsx, 11, 5))
27+
28+
<public></public>
29+
>public : Symbol(JSX.IntrinsicElements, Decl(a.tsx, 1, 23))
30+
>public : Symbol(JSX.IntrinsicElements, Decl(a.tsx, 1, 23))
31+
32+
);
33+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
=== tests/cases/conformance/jsx/a.tsx ===
2+
declare const React: any
3+
>React : any
4+
5+
declare namespace JSX {
6+
interface IntrinsicElements {
7+
[k: string]: any
8+
>k : string
9+
}
10+
}
11+
12+
const a = (
13+
>a : error
14+
>( <public-foo></public-foo>) : error
15+
16+
<public-foo></public-foo>
17+
><public-foo></public-foo> : error
18+
>public-foo : any
19+
>public-foo : any
20+
21+
);
22+
23+
const b = (
24+
>b : error
25+
>( <public></public>) : error
26+
27+
<public></public>
28+
><public></public> : error
29+
>public : any
30+
>public : any
31+
32+
);
33+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
tests/cases/conformance/jsx/a.tsx(13,4): error TS1212: Identifier expected. 'public' is a reserved word in strict mode.
2+
tests/cases/conformance/jsx/a.tsx(13,13): error TS1212: Identifier expected. 'public' is a reserved word in strict mode.
3+
4+
5+
==== tests/cases/conformance/jsx/a.tsx (2 errors) ====
6+
declare const React: any
7+
declare namespace JSX {
8+
interface IntrinsicElements {
9+
[k: string]: any
10+
}
11+
}
12+
13+
const a = (
14+
<public-foo></public-foo>
15+
);
16+
17+
const b = (
18+
<public></public>
19+
~~~~~~
20+
!!! error TS1212: Identifier expected. 'public' is a reserved word in strict mode.
21+
~~~~~~
22+
!!! error TS1212: Identifier expected. 'public' is a reserved word in strict mode.
23+
);
24+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
//// [a.tsx]
2+
declare const React: any
3+
declare namespace JSX {
4+
interface IntrinsicElements {
5+
[k: string]: any
6+
}
7+
}
8+
9+
const a = (
10+
<public-foo></public-foo>
11+
);
12+
13+
const b = (
14+
<public></public>
15+
);
16+
17+
18+
//// [a.js]
19+
"use strict";
20+
var a = (React.createElement("public-foo", null));
21+
var b = (React.createElement("public", null));
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
=== tests/cases/conformance/jsx/a.tsx ===
2+
declare const React: any
3+
>React : Symbol(React, Decl(a.tsx, 0, 13))
4+
5+
declare namespace JSX {
6+
>JSX : Symbol(JSX, Decl(a.tsx, 0, 24))
7+
8+
interface IntrinsicElements {
9+
>IntrinsicElements : Symbol(IntrinsicElements, Decl(a.tsx, 1, 23))
10+
11+
[k: string]: any
12+
>k : Symbol(k, Decl(a.tsx, 3, 9))
13+
}
14+
}
15+
16+
const a = (
17+
>a : Symbol(a, Decl(a.tsx, 7, 5))
18+
19+
<public-foo></public-foo>
20+
>public-foo : Symbol(JSX.IntrinsicElements, Decl(a.tsx, 1, 23))
21+
>public-foo : Symbol(JSX.IntrinsicElements, Decl(a.tsx, 1, 23))
22+
23+
);
24+
25+
const b = (
26+
>b : Symbol(b, Decl(a.tsx, 11, 5))
27+
28+
<public></public>
29+
>public : Symbol(JSX.IntrinsicElements, Decl(a.tsx, 1, 23))
30+
>public : Symbol(JSX.IntrinsicElements, Decl(a.tsx, 1, 23))
31+
32+
);
33+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
=== tests/cases/conformance/jsx/a.tsx ===
2+
declare const React: any
3+
>React : any
4+
5+
declare namespace JSX {
6+
interface IntrinsicElements {
7+
[k: string]: any
8+
>k : string
9+
}
10+
}
11+
12+
const a = (
13+
>a : any
14+
>( <public-foo></public-foo>) : any
15+
16+
<public-foo></public-foo>
17+
><public-foo></public-foo> : any
18+
>public-foo : any
19+
>public-foo : any
20+
21+
);
22+
23+
const b = (
24+
>b : any
25+
>( <public></public>) : any
26+
27+
<public></public>
28+
><public></public> : any
29+
>public : any
30+
>public : any
31+
32+
);
33+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
// @strict: true, false
2+
// @jsx: react
3+
// @filename: a.tsx
4+
5+
declare const React: any
6+
declare namespace JSX {
7+
interface IntrinsicElements {
8+
[k: string]: any
9+
}
10+
}
11+
12+
const a = (
13+
<public-foo></public-foo>
14+
);
15+
16+
const b = (
17+
<public></public>
18+
);

0 commit comments

Comments
 (0)