8000 allow jsx identifiers to start with keywords by vladima · Pull Request #4705 · microsoft/TypeScript · GitHub
[go: up one dir, main page]

Skip to content

allow jsx identifiers to start with keywords #4705

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Sep 10, 2015
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
allow to use keywords as jsx identifiers
  • Loading branch information
vladima committed Sep 9, 2015
commit aa29644c2a17a9ea20aca894bf67c44c78f46b2d
6 changes: 5 additions & 1 deletion src/compiler/parser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@ namespace ts {
export function createNode(kind: SyntaxKind): Node {
return new (getNodeConstructor(kind))();
}

export function tokenIsIdentifierOrKeyword(token: SyntaxKind): boolean {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be exported from the scanner (and marked internal).

return token >= SyntaxKind.Identifier;
}

function visitNode<T>(cbNode: (node: Node) => T, node: Node): T {
if (node) {
Expand Down Expand Up @@ -4102,7 +4106,7 @@ namespace ts {
}

function isIdentifierOrKeyword() {
return token >= SyntaxKind.Identifier;
return tokenIsIdentifierOrKeyword(token);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do you need this function then?

}

function nextTokenIsIdentifierOrKeywordOnSameLine() {
Expand Down
2 changes: 1 addition & 1 deletion src/compiler/scanner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
7 changes: 7 additions & 0 deletions tests/baselines/reference/keywordInJsxIdentifier.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
//// [keywordInJsxIdentifier.tsx]

declare var React: any;
<foo class-id/>

//// [keywordInJsxIdentifier.js]
React.createElement("foo", {"class-id": true});
8 changes: 8 additions & 0 deletions tests/baselines/reference/keywordInJsxIdentifier.symbols
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
=== tests/cases/compiler/keywordInJsxIdentifier.tsx ===

declare var React: any;
>React : Symbol(React, Decl(keywordInJsxIdentifier.tsx, 1, 11))

8000 <foo class-id/>
>class-id : Symbol(unknown)

10 changes: 10 additions & 0 deletions tests/baselines/reference/keywordInJsxIdentifier.types
Original file line number Diff line number Diff line change
@@ -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 changes: 4 additions & 0 deletions tests/cases/compiler/keywordInJsxIdentifier.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
//@jsx: react

declare var React: any;
<foo class-id/>
0