allow to use keywords as jsx identifiers
This commit is contained in:
parent
971c777031
commit
aa29644c2a
|
@ -12,6 +12,10 @@ namespace ts {
|
||||||
export function createNode(kind: SyntaxKind): Node {
|
export function createNode(kind: SyntaxKind): Node {
|
||||||
return new (getNodeConstructor(kind))();
|
return new (getNodeConstructor(kind))();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function tokenIsIdentifierOrKeyword(token: SyntaxKind): boolean {
|
||||||
|
return token >= SyntaxKind.Identifier;
|
||||||
|
}
|
||||||
|
|
||||||
function visitNode<T>(cbNode: (node: Node) => T, node: Node): T {
|
function visitNode<T>(cbNode: (node: Node) => T, node: Node): T {
|
||||||
if (node) {
|
if (node) {
|
||||||
|
@ -4102,7 +4106,7 @@ namespace ts {
|
||||||
}
|
}
|
||||||
|
|
||||||
function isIdentifierOrKeyword() {
|
function isIdentifierOrKeyword() {
|
||||||
return token >= SyntaxKind.Identifier;
|
return tokenIsIdentifierOrKeyword(token);
|
||||||
}
|
}
|
||||||
|
|
||||||
function nextTokenIsIdentifierOrKeywordOnSameLine() {
|
function nextTokenIsIdentifierOrKeywordOnSameLine() {
|
||||||
|
|
|
@ -1590,7 +1590,7 @@ namespace ts {
|
||||||
// Scans a JSX identifier; these differ from normal identifiers in that
|
// Scans a JSX identifier; these differ from normal identifiers in that
|
||||||
// they allow dashes
|
// they allow dashes
|
||||||
function scanJsxIdentifier(): SyntaxKind {
|
function scanJsxIdentifier(): SyntaxKind {
|
||||||
if (token === SyntaxKind.Identifier) {
|
if (tokenIsIdentifierOrKeyword(token)) {
|
||||||
let firstCharPosition = pos;
|
let firstCharPosition = pos;
|
||||||
while (pos < end) {
|
while (pos < end) {
|
||||||
let ch = text.charCodeAt(pos);
|
let ch = text.charCodeAt(pos);
|
||||||
|
|
7
tests/baselines/reference/keywordInJsxIdentifier.js
Normal file
7
tests/baselines/reference/keywordInJsxIdentifier.js
Normal file
|
@ -0,0 +1,7 @@
|
||||||
|
//// [keywordInJsxIdentifier.tsx]
|
||||||
|
|
||||||
|
declare var React: any;
|
||||||
|
<foo class-id/>
|
||||||
|
|
||||||
|
//// [keywordInJsxIdentifier.js]
|
||||||
|
React.createElement("foo", {"class-id": true});
|
8
tests/baselines/reference/keywordInJsxIdentifier.symbols
Normal file
8
tests/baselines/reference/keywordInJsxIdentifier.symbols
Normal 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)
|
||||||
|
|
10
tests/baselines/reference/keywordInJsxIdentifier.types
Normal file
10
tests/baselines/reference/keywordInJsxIdentifier.types
Normal 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
|
||||||
|
|
4
tests/cases/compiler/keywordInJsxIdentifier.tsx
Normal file
4
tests/cases/compiler/keywordInJsxIdentifier.tsx
Normal file
|
@ -0,0 +1,4 @@
|
||||||
|
//@jsx: react
|
||||||
|
|
||||||
|
declare var React: any;
|
||||||
|
<foo class-id/>
|
Loading…
Reference in a new issue