allow to use keywords as jsx identifiers

This commit is contained in:
Vladimir Matveev 2015-09-08 22:40:16 -07:00
parent 971c777031
commit aa29644c2a
6 changed files with 35 additions and 2 deletions

View file

@ -12,6 +12,10 @@ namespace ts {
export function createNode(kind: SyntaxKind): Node {
return new (getNodeConstructor(kind))();
}
export function tokenIsIdentifierOrKeyword(token: SyntaxKind): boolean {
return token >= SyntaxKind.Identifier;
}
function visitNode<T>(cbNode: (node: Node) => T, node: Node): T {
if (node) {
@ -4102,7 +4106,7 @@ namespace ts {
}
function isIdentifierOrKeyword() {
return token >= SyntaxKind.Identifier;
return tokenIsIdentifierOrKeyword(token);
}
function nextTokenIsIdentifierOrKeywordOnSameLine() {

View file

@ -1590,7 +1590,7 @@ namespace ts {
// Scans a JSX identifier; these differ from normal identifiers in that
// they allow dashes
function scanJsxIdentifier(): SyntaxKind {
if (token === SyntaxKind.Identifier) {
if (tokenIsIdentifierOrKeyword(token)) {
let firstCharPosition = pos;
while (pos < end) {
let ch = text.charCodeAt(pos);

View file

@ -0,0 +1,7 @@
//// [keywordInJsxIdentifier.tsx]
declare var React: any;
<foo class-id/>
//// [keywordInJsxIdentifier.js]
React.createElement("foo", {"class-id": true});

View file

@ -0,0 +1,8 @@
=== tests/cases/compiler/keywordInJsxIdentifier.tsx ===
declare var React: any;
>React : Symbol(React, Decl(keywordInJsxIdentifier.tsx, 1, 11))
<foo class-id/>
>class-id : Symbol(unknown)

View file

@ -0,0 +1,10 @@
=== tests/cases/compiler/keywordInJsxIdentifier.tsx ===
declare var React: any;
>React : any
<foo class-id/>
><foo class-id/> : any
>foo : any
>class-id : any

View file

@ -0,0 +1,4 @@
//@jsx: react
declare var React: any;
<foo class-id/>