Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
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
4 changes: 4 additions & 0 deletions tsc/internal/parser/parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -5981,6 +5981,10 @@ func (p *Parser) parseIdentifierNameErrorOnUnicodeEscapeSequence() *ast.Node {
if p.scanner.HasUnicodeEscape() || p.scanner.HasExtendedUnicodeEscape() {
p.parseErrorAtCurrentToken(diagnostics.Unicode_escape_sequence_cannot_appear_here)
}
if p.token == ast.KindPrivateIdentifier {
// tokenIsIdentifierOrKeyword accepts private identifiers, but '#' is not a valid JSX identifier character.
return p.createIdentifierWithDiagnostic(false /*isIdentifier*/, nil /*diagnosticMessage*/, diagnostics.Identifier_expected)
}
return p.createIdentifier(tokenIsIdentifierOrKeyword(p.token))
}

Expand Down
3 changes: 2 additions & 1 deletion tsc/internal/scanner/scanner.go
Original file line number Diff line number Diff line change
Expand Up @@ -1370,7 +1370,8 @@ func (s *Scanner) ScanJsxTokenEx(allowMultilineJsxText bool) ast.Kind {

// Scans a JSX identifier; these differ from normal identifiers in that they allow dashes
func (s *Scanner) ScanJsxIdentifier() ast.Kind {
if tokenIsIdentifierOrKeyword(s.token) {
// Private identifiers are not valid JSX identifiers; leave them for the parser to report.
if tokenIsIdentifierOrKeyword(s.token) && s.token != ast.KindPrivateIdentifier {
// An identifier or keyword has already been parsed - check for a `-` or a single instance of `:` and then append it and
// everything after it to the token
// Do note that this means that `scanJsxIdentifier` effectively _mutates_ the visible token without advancing to a new token
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
jsxPrivateIdentifierNames.tsx(8,12): error TS1003: Identifier expected.
jsxPrivateIdentifierNames.tsx(8,12): error TS2304: Cannot find name '#a'.
jsxPrivateIdentifierNames.tsx(8,17): error TS1003: Identifier expected.
jsxPrivateIdentifierNames.tsx(8,17): error TS2304: Cannot find name '#a'.
jsxPrivateIdentifierNames.tsx(9,12): error TS1003: Identifier expected.
jsxPrivateIdentifierNames.tsx(9,12): error TS2304: Cannot find name '#b'.
jsxPrivateIdentifierNames.tsx(10,16): error TS1003: Identifier expected.
jsxPrivateIdentifierNames.tsx(11,16): error TS1003: Identifier expected.
jsxPrivateIdentifierNames.tsx(12,16): error TS1003: Identifier expected.
jsxPrivateIdentifierNames.tsx(13,18): error TS1003: Identifier expected.
jsxPrivateIdentifierNames.tsx(14,14): error TS1003: Identifier expected.
jsxPrivateIdentifierNames.tsx(15,12): error TS1003: Identifier expected.
jsxPrivateIdentifierNames.tsx(16,16): error TS1003: Identifier expected.


==== jsxPrivateIdentifierNames.tsx (13 errors) ====
declare const React: any;
declare namespace JSX {
interface IntrinsicElements {
[name: string]: any;
}
}

const a = <#a></#a>;
~~
!!! error TS1003: Identifier expected.
~~
!!! error TS2304: Cannot find name '#a'.
~~
!!! error TS1003: Identifier expected.
~~
!!! error TS2304: Cannot find name '#a'.
const b = <#b />;
~~
!!! error TS1003: Identifier expected.
~~
!!! error TS2304: Cannot find name '#b'.
const c = <div #c />;
~~
!!! error TS1003: Identifier expected.
const d = <div #d="d" />;
~~
!!! error TS1003: Identifier expected.
const e = <div #e:f />;
~~
!!! error TS1003: Identifier expected.
const f = <div f:#g />;
~~
!!! error TS1003: Identifier expected.
const g = <a:#h />;
~~
!!! error TS1003: Identifier expected.
const h = <#i:j />;
~~
!!! error TS1003: Identifier expected.
const i = <a.#k />;

!!! error TS1003: Identifier expected.

Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
//// [tests/cases/compiler/jsxPrivateIdentifierNames.tsx] ////

//// [jsxPrivateIdentifierNames.tsx]
declare const React: any;
declare namespace JSX {
interface IntrinsicElements {
[name: string]: any;
}
}

const a = <#a></#a>;
const b = <#b />;
const c = <div #c />;
const d = <div #d="d" />;
const e = <div #e:f />;
const f = <div f:#g />;
const g = <a:#h />;
const h = <#i:j />;
const i = <a.#k />;


//// [jsxPrivateIdentifierNames.jsx]
"use strict";
const a = <#a></#a>;
const b = <#b />;
const c = <div #c/>;
const d = <div #d="d"/>;
const e = <div #e:f/>;
const f = <div f:#g/>;
const g = <a:#h />;
const h = <#i:j />;
const i = <a. />;
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
//// [tests/cases/compiler/jsxPrivateIdentifierNames.tsx] ////

=== jsxPrivateIdentifierNames.tsx ===
declare const React: any;
>React : Symbol(React, Decl(jsxPrivateIdentifierNames.tsx, 0, 13))

declare namespace JSX {
>JSX : Symbol(JSX, Decl(jsxPrivateIdentifierNames.tsx, 0, 25))

interface IntrinsicElements {
>IntrinsicElements : Symbol(IntrinsicElements, Decl(jsxPrivateIdentifierNames.tsx, 1, 23))

[name: string]: any;
>name : Symbol(name, Decl(jsxPrivateIdentifierNames.tsx, 3, 9))
}
}

const a = <#a></#a>;
>a : Symbol(a, Decl(jsxPrivateIdentifierNames.tsx, 7, 5))

const b = <#b />;
>b : Symbol(b, Decl(jsxPrivateIdentifierNames.tsx, 8, 5))

const c = <div #c />;
>c : Symbol(c, Decl(jsxPrivateIdentifierNames.tsx, 9, 5))
>div : Symbol(JSX.IntrinsicElements.__index, Decl(jsxPrivateIdentifierNames.tsx, 2, 33))
>#c : Symbol(#c, Decl(jsxPrivateIdentifierNames.tsx, 9, 14))

const d = <div #d="d" />;
>d : Symbol(d, Decl(jsxPrivateIdentifierNames.tsx, 10, 5))
>div : Symbol(JSX.IntrinsicElements.__index, Decl(jsxPrivateIdentifierNames.tsx, 2, 33))
>#d : Symbol(#d, Decl(jsxPrivateIdentifierNames.tsx, 10, 14))

const e = <div #e:f />;
>e : Symbol(e, Decl(jsxPrivateIdentifierNames.tsx, 11, 5))
>div : Symbol(JSX.IntrinsicElements.__index, Decl(jsxPrivateIdentifierNames.tsx, 2, 33))
>#e:f : Symbol(#e:f, Decl(jsxPrivateIdentifierNames.tsx, 11, 14))

const f = <div f:#g />;
>f : Symbol(f, Decl(jsxPrivateIdentifierNames.tsx, 12, 5))
>div : Symbol(JSX.IntrinsicElements.__index, Decl(jsxPrivateIdentifierNames.tsx, 2, 33))
>f:#g : Symbol(f:#g, Decl(jsxPrivateIdentifierNames.tsx, 12, 14))

const g = <a:#h />;
>g : Symbol(g, Decl(jsxPrivateIdentifierNames.tsx, 13, 5))

const h = <#i:j />;
>h : Symbol(h, Decl(jsxPrivateIdentifierNames.tsx, 14, 5))

const i = <a.#k />;
>i : Symbol(i, Decl(jsxPrivateIdentifierNames.tsx, 15, 5))
>a : Symbol(a, Decl(jsxPrivateIdentifierNames.tsx, 7, 5))

Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
//// [tests/cases/compiler/jsxPrivateIdentifierNames.tsx] ////

=== jsxPrivateIdentifierNames.tsx ===
declare const React: any;
>React : any

declare namespace JSX {
interface IntrinsicElements {
[name: string]: any;
>name : string
}
}

const a = <#a></#a>;
>a : any
><#a></#a> : any
>#a : any
>#a : any

const b = <#b />;
>b : any
><#b /> : any
>#b : any

const c = <div #c />;
>c : any
><div #c /> : any
>div : any
>#c : true

const d = <div #d="d" />;
>d : any
><div #d="d" /> : any
>div : any
>#d : string

const e = <div #e:f />;
>e : any
><div #e:f /> : any
>div : any
>#e:f : true
>#e : any
>f : any

const f = <div f:#g />;
>f : any
><div f:#g /> : any
>div : any
>f:#g : true
>f : any
>#g : any

const g = <a:#h />;
>g : any
><a:#h /> : any
>a : any
>#h : any

const h = <#i:j />;
>h : any
><#i:j /> : any
>#i : any
>j : any

const i = <a.#k />;
>i : any
><a.#k /> : any
>a.#k : any
>a : any
> : any

Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
jsxPrivateIdentifierNames.tsx(8,12): error TS1003: Identifier expected.
jsxPrivateIdentifierNames.tsx(8,12): error TS2304: Cannot find name '#a'.
jsxPrivateIdentifierNames.tsx(8,17): error TS1003: Identifier expected.
jsxPrivateIdentifierNames.tsx(8,17): error TS2304: Cannot find name '#a'.
jsxPrivateIdentifierNames.tsx(9,12): error TS1003: Identifier expected.
jsxPrivateIdentifierNames.tsx(9,12): error TS2304: Cannot find name '#b'.
jsxPrivateIdentifierNames.tsx(10,16): error TS1003: Identifier expected.
jsxPrivateIdentifierNames.tsx(11,16): error TS1003: Identifier expected.
jsxPrivateIdentifierNames.tsx(12,16): error TS1003: Identifier expected.
jsxPrivateIdentifierNames.tsx(13,18): error TS1003: Identifier expected.
jsxPrivateIdentifierNames.tsx(14,14): error TS1003: Identifier expected.
jsxPrivateIdentifierNames.tsx(15,12): error TS1003: Identifier expected.
jsxPrivateIdentifierNames.tsx(16,16): error TS1003: Identifier expected.


==== jsxPrivateIdentifierNames.tsx (13 errors) ====
declare const React: any;
declare namespace JSX {
interface IntrinsicElements {
[name: string]: any;
}
}

const a = <#a></#a>;
~~
!!! error TS1003: Identifier expected.
~~
!!! error TS2304: Cannot find name '#a'.
~~
!!! error TS1003: Identifier expected.
~~
!!! error TS2304: Cannot find name '#a'.
const b = <#b />;
~~
!!! error TS1003: Identifier expected.
~~
!!! error TS2304: Cannot find name '#b'.
const c = <div #c />;
~~
!!! error TS1003: Identifier expected.
const d = <div #d="d" />;
~~
!!! error TS1003: Identifier expected.
const e = <div #e:f />;
~~
!!! error TS1003: Identifier expected.
const f = <div f:#g />;
~~
!!! error TS1003: Identifier expected.
const g = <a:#h />;
~~
!!! error TS1003: Identifier expected.
const h = <#i:j />;
~~
!!! error TS1003: Identifier expected.
const i = <a.#k />;

!!! error TS1003: Identifier expected.

Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
//// [tests/cases/compiler/jsxPrivateIdentifierNames.tsx] ////

//// [jsxPrivateIdentifierNames.tsx]
declare const React: any;
declare namespace JSX {
interface IntrinsicElements {
[name: string]: any;
}
}

const a = <#a></#a>;
const b = <#b />;
const c = <div #c />;
const d = <div #d="d" />;
const e = <div #e:f />;
const f = <div f:#g />;
const g = <a:#h />;
const h = <#i:j />;
const i = <a.#k />;


//// [jsxPrivateIdentifierNames.js]
"use strict";
const a = React.createElement(#a, null);
const b = React.createElement(#b, null);
const c = React.createElement("div", { "#c": true });
const d = React.createElement("div", { "#d": "d" });
const e = React.createElement("div", { "#e:f": true });
const f = React.createElement("div", { "f:#g": true });
const g = React.createElement("a:#h", null);
const h = React.createElement("#i:j", null);
const i = React.createElement(a., null);
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
//// [tests/cases/compiler/jsxPrivateIdentifierNames.tsx] ////

=== jsxPrivateIdentifierNames.tsx ===
declare const React: any;
>React : Symbol(React, Decl(jsxPrivateIdentifierNames.tsx, 0, 13))

declare namespace JSX {
>JSX : Symbol(JSX, Decl(jsxPrivateIdentifierNames.tsx, 0, 25))

interface IntrinsicElements {
>IntrinsicElements : Symbol(IntrinsicElements, Decl(jsxPrivateIdentifierNames.tsx, 1, 23))

[name: string]: any;
>name : Symbol(name, Decl(jsxPrivateIdentifierNames.tsx, 3, 9))
}
}

const a = <#a></#a>;
>a : Symbol(a, Decl(jsxPrivateIdentifierNames.tsx, 7, 5))

const b = <#b />;
>b : Symbol(b, Decl(jsxPrivateIdentifierNames.tsx, 8, 5))

const c = <div #c />;
>c : Symbol(c, Decl(jsxPrivateIdentifierNames.tsx, 9, 5))
>div : Symbol(JSX.IntrinsicElements.__index, Decl(jsxPrivateIdentifierNames.tsx, 2, 33))
>#c : Symbol(#c, Decl(jsxPrivateIdentifierNames.tsx, 9, 14))

const d = <div #d="d" />;
>d : Symbol(d, Decl(jsxPrivateIdentifierNames.tsx, 10, 5))
>div : Symbol(JSX.IntrinsicElements.__index, Decl(jsxPrivateIdentifierNames.tsx, 2, 33))
>#d : Symbol(#d, Decl(jsxPrivateIdentifierNames.tsx, 10, 14))

const e = <div #e:f />;
>e : Symbol(e, Decl(jsxPrivateIdentifierNames.tsx, 11, 5))
>div : Symbol(JSX.IntrinsicElements.__index, Decl(jsxPrivateIdentifierNames.tsx, 2, 33))
>#e:f : Symbol(#e:f, Decl(jsxPrivateIdentifierNames.tsx, 11, 14))

const f = <div f:#g />;
>f : Symbol(f, Decl(jsxPrivateIdentifierNames.tsx, 12, 5))
>div : Symbol(JSX.IntrinsicElements.__index, Decl(jsxPrivateIdentifierNames.tsx, 2, 33))
>f:#g : Symbol(f:#g, Decl(jsxPrivateIdentifierNames.tsx, 12, 14))

const g = <a:#h />;
>g : Symbol(g, Decl(jsxPrivateIdentifierNames.tsx, 13, 5))

const h = <#i:j />;
>h : Symbol(h, Decl(jsxPrivateIdentifierNames.tsx, 14, 5))

const i = <a.#k />;
>i : Symbol(i, Decl(jsxPrivateIdentifierNames.tsx, 15, 5))
>a : Symbol(a, Decl(jsxPrivateIdentifierNames.tsx, 7, 5))

Loading