Skip to content

Commit aa29644

Browse files
committed
allow to use keywords as jsx identifiers
1 parent 971c777 commit aa29644

File tree

6 files changed

+35
-2
lines changed

6 files changed

+35
-2
lines changed

src/compiler/parser.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,10 @@ namespace ts {
1212
export function createNode(kind: SyntaxKind): Node {
1313
return new (getNodeConstructor(kind))();
1414
}
15+
16+
export function tokenIsIdentifierOrKeyword(token: SyntaxKind): boolean {
17+
return token >= SyntaxKind.Identifier;
18+
}
1519

1620
function visitNode<T>(cbNode: (node: Node) => T, node: Node): T {
1721
if (node) {
@@ -4102,7 +4106,7 @@ namespace ts {
41024106
}
41034107

41044108
function isIdentifierOrKeyword() {
4105-
return token >= SyntaxKind.Identifier;
4109+
return tokenIsIdentifierOrKeyword(token);
41064110
}
41074111

41084112
function nextTokenIsIdentifierOrKeywordOnSameLine() {

src/compiler/scanner.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1590,7 +1590,7 @@ namespace ts {
15901590
// Scans a JSX identifier; these differ from normal identifiers in that
15911591
// they allow dashes
15921592
function scanJsxIdentifier(): SyntaxKind {
1593-
if (token === SyntaxKind.Identifier) {
1593+
if (tokenIsIdentifierOrKeyword(token)) {
15941594
let firstCharPosition = pos;
15951595
while (pos < end) {
15961596
let ch = text.charCodeAt(pos);
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
//// [keywordInJsxIdentifier.tsx]
2+
3+
declare var React: any;
4+
<foo class-id/>
5+
6+
//// [keywordInJsxIdentifier.js]
7+
React.createElement("foo", {"class-id": true});
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
=== tests/cases/compiler/keywordInJsxIdentifier.tsx ===
2+
3+
declare var React: any;
4+
>React : Symbol(React, Decl(keywordInJsxIdentifier.tsx, 1, 11))
5+
6+
<foo class-id/>
7+
>class-id : Symbol(unknown)
8+
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
=== tests/cases/compiler/keywordInJsxIdentifier.tsx ===
2+
3+
declare var React: any;
4+
>React : any
5+
6+
<foo class-id/>
7+
><foo class-id/> : any
8+
>foo : any
9+
>class-id : any
10+
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
//@jsx: react
2+
3+
declare var React: any;
4+
<foo class-id/>

0 commit comments

Comments
 (0)