diff --git a/tsc/internal/parser/parser.go b/tsc/internal/parser/parser.go
index a58db02e5c70f..fbf071271cfd8 100644
--- a/tsc/internal/parser/parser.go
+++ b/tsc/internal/parser/parser.go
@@ -5147,10 +5147,10 @@ func (p *Parser) parseJsxTagName() *ast.Expression {
pos := p.nodePos()
p.scanJsxIdentifier()
isThis := p.token == ast.KindThisKeyword
- tagName := p.parseIdentifierNameErrorOnUnicodeEscapeSequence()
+ tagName := p.parseJsxIdentifierName()
if p.parseOptional(ast.KindColonToken) {
p.scanJsxIdentifier()
- return p.finishNode(p.factory.NewJsxNamespacedName(tagName, p.parseIdentifierNameErrorOnUnicodeEscapeSequence()), pos)
+ return p.finishNode(p.factory.NewJsxNamespacedName(tagName, p.parseJsxIdentifierName()), pos)
}
if isThis {
result := p.factory.NewKeywordExpression(ast.KindThisKeyword)
@@ -5159,6 +5159,17 @@ func (p *Parser) parseJsxTagName() *ast.Expression {
return tagName
}
+func (p *Parser) parseJsxIdentifierName() *ast.Node {
+ if p.token == ast.KindPrivateIdentifier {
+ // '#' is not a valid JSX identifier character. Consume the private identifier and produce a missing
+ // identifier, as parseRightSideOfDot does for ``.
+ p.parseErrorAtCurrentToken(diagnostics.Identifier_expected)
+ p.nextToken()
+ return p.createMissingIdentifier()
+ }
+ return p.parseIdentifierNameErrorOnUnicodeEscapeSequence()
+}
+
func (p *Parser) parseJsxAttributes() *ast.Node {
pos := p.nodePos()
return p.finishNode(p.factory.NewJsxAttributes(p.parseList(PCJsxAttributes, (*Parser).parseJsxAttribute)), pos)
@@ -5184,10 +5195,10 @@ func (p *Parser) parseJsxSpreadAttribute() *ast.Node {
func (p *Parser) parseJsxAttributeName() *ast.Node {
pos := p.nodePos()
p.scanJsxIdentifier()
- attrName := p.parseIdentifierNameErrorOnUnicodeEscapeSequence()
+ attrName := p.parseJsxIdentifierName()
if p.parseOptional(ast.KindColonToken) {
p.scanJsxIdentifier()
- return p.finishNode(p.factory.NewJsxNamespacedName(attrName, p.parseIdentifierNameErrorOnUnicodeEscapeSequence()), pos)
+ return p.finishNode(p.factory.NewJsxNamespacedName(attrName, p.parseJsxIdentifierName()), pos)
}
return attrName
}
diff --git a/tsc/internal/scanner/scanner.go b/tsc/internal/scanner/scanner.go
index 7dc5199678d93..884c280de1bfd 100644
--- a/tsc/internal/scanner/scanner.go
+++ b/tsc/internal/scanner/scanner.go
@@ -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) {
+ // '#' is not a valid JSX identifier character, so a private identifier is left for the parser to report.
+ if s.token != ast.KindPrivateIdentifier && tokenIsIdentifierOrKeyword(s.token) {
// 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
diff --git a/tsc/testdata/baselines/reference/compiler/jsxNamesStartingWithHash(jsx=preserve).errors.txt b/tsc/testdata/baselines/reference/compiler/jsxNamesStartingWithHash(jsx=preserve).errors.txt
new file mode 100644
index 0000000000000..efd5915050fc0
--- /dev/null
+++ b/tsc/testdata/baselines/reference/compiler/jsxNamesStartingWithHash(jsx=preserve).errors.txt
@@ -0,0 +1,57 @@
+jsxNamesStartingWithHash.tsx(8,12): error TS1003: Identifier expected.
+jsxNamesStartingWithHash.tsx(8,17): error TS1003: Identifier expected.
+jsxNamesStartingWithHash.tsx(9,16): error TS1003: Identifier expected.
+jsxNamesStartingWithHash.tsx(10,16): error TS1003: Identifier expected.
+jsxNamesStartingWithHash.tsx(11,16): error TS1003: Identifier expected.
+jsxNamesStartingWithHash.tsx(12,14): error TS1003: Identifier expected.
+jsxNamesStartingWithHash.tsx(13,16): error TS1003: Identifier expected.
+jsxNamesStartingWithHash.tsx(14,12): error TS1003: Identifier expected.
+jsxNamesStartingWithHash.tsx(15,18): error TS1003: Identifier expected.
+jsxNamesStartingWithHash.tsx(16,16): error TS1003: Identifier expected.
+jsxNamesStartingWithHash.tsx(16,19): error TS1003: Identifier expected.
+jsxNamesStartingWithHash.tsx(17,12): error TS1127: Invalid character.
+
+
+==== jsxNamesStartingWithHash.tsx (12 errors) ====
+ declare const React: any;
+ declare namespace JSX {
+ interface IntrinsicElements {
+ [name: string]: any;
+ }
+ }
+
+ const a = <#a>#a>;
+ ~~
+!!! error TS1003: Identifier expected.
+ ~~
+!!! error TS1003: Identifier expected.
+ const b =
;
+ ~~
+!!! error TS1003: Identifier expected.
+ const c = ;
+ ~~
+!!! error TS1003: Identifier expected.
+ const d = ;
+ ~~
+!!! error TS1003: Identifier expected.
+ const e = ;
+ ~~
+!!! error TS1003: Identifier expected.
+ const f = ;
+
+!!! error TS1003: Identifier expected.
+ const g = <#h:i />;
+ ~~
+!!! error TS1003: Identifier expected.
+ const h = ;
+ ~~
+!!! error TS1003: Identifier expected.
+ const i = ;
+ ~~
+!!! error TS1003: Identifier expected.
+ ~~
+!!! error TS1003: Identifier expected.
+ const j = <# />;
+ ~
+!!! error TS1127: Invalid character.
+
\ No newline at end of file
diff --git a/tsc/testdata/baselines/reference/compiler/jsxNamesStartingWithHash(jsx=preserve).js b/tsc/testdata/baselines/reference/compiler/jsxNamesStartingWithHash(jsx=preserve).js
new file mode 100644
index 0000000000000..d5c909ff59100
--- /dev/null
+++ b/tsc/testdata/baselines/reference/compiler/jsxNamesStartingWithHash(jsx=preserve).js
@@ -0,0 +1,34 @@
+//// [tests/cases/compiler/jsxNamesStartingWithHash.tsx] ////
+
+//// [jsxNamesStartingWithHash.tsx]
+declare const React: any;
+declare namespace JSX {
+ interface IntrinsicElements {
+ [name: string]: any;
+ }
+}
+
+const a = <#a>#a>;
+const b = ;
+const c = ;
+const d = ;
+const e = ;
+const f = ;
+const g = <#h:i />;
+const h = ;
+const i = ;
+const j = <# />;
+
+
+//// [jsxNamesStartingWithHash.jsx]
+"use strict";
+const a = <>>;
+const b = ;
+const c = ;
+const d = ;
+const e = ;
+const f = ;
+const g = <:i />;
+const h = ;
+const i = ;
+const j = < />;
diff --git a/tsc/testdata/baselines/reference/compiler/jsxNamesStartingWithHash(jsx=preserve).symbols b/tsc/testdata/baselines/reference/compiler/jsxNamesStartingWithHash(jsx=preserve).symbols
new file mode 100644
index 0000000000000..f3e62d63b8403
--- /dev/null
+++ b/tsc/testdata/baselines/reference/compiler/jsxNamesStartingWithHash(jsx=preserve).symbols
@@ -0,0 +1,60 @@
+//// [tests/cases/compiler/jsxNamesStartingWithHash.tsx] ////
+
+=== jsxNamesStartingWithHash.tsx ===
+declare const React: any;
+>React : Symbol(React, Decl(jsxNamesStartingWithHash.tsx, 0, 13))
+
+declare namespace JSX {
+>JSX : Symbol(JSX, Decl(jsxNamesStartingWithHash.tsx, 0, 25))
+
+ interface IntrinsicElements {
+>IntrinsicElements : Symbol(IntrinsicElements, Decl(jsxNamesStartingWithHash.tsx, 1, 23))
+
+ [name: string]: any;
+>name : Symbol(name, Decl(jsxNamesStartingWithHash.tsx, 3, 9))
+ }
+}
+
+const a = <#a>#a>;
+>a : Symbol(a, Decl(jsxNamesStartingWithHash.tsx, 7, 5))
+
+const b = ;
+>b : Symbol(b, Decl(jsxNamesStartingWithHash.tsx, 8, 5))
+>div : Symbol(JSX.IntrinsicElements.__index, Decl(jsxNamesStartingWithHash.tsx, 2, 33))
+> : Symbol((Missing), Decl(jsxNamesStartingWithHash.tsx, 8, 14))
+
+const c = ;
+>c : Symbol(c, Decl(jsxNamesStartingWithHash.tsx, 9, 5))
+>div : Symbol(JSX.IntrinsicElements.__index, Decl(jsxNamesStartingWithHash.tsx, 2, 33))
+> : Symbol((Missing), Decl(jsxNamesStartingWithHash.tsx, 9, 14))
+
+const d = ;
+>d : Symbol(d, Decl(jsxNamesStartingWithHash.tsx, 10, 5))
+>div : Symbol(JSX.IntrinsicElements.__index, Decl(jsxNamesStartingWithHash.tsx, 2, 33))
+>#d:e : Symbol(#d:e, Decl(jsxNamesStartingWithHash.tsx, 10, 14))
+
+const e = ;
+>e : Symbol(e, Decl(jsxNamesStartingWithHash.tsx, 11, 5))
+
+const f = ;
+>f : Symbol(f, Decl(jsxNamesStartingWithHash.tsx, 12, 5))
+>a : Symbol(a, Decl(jsxNamesStartingWithHash.tsx, 7, 5))
+
+const g = <#h:i />;
+>g : Symbol(g, Decl(jsxNamesStartingWithHash.tsx, 13, 5))
+
+const h = ;
+>h : Symbol(h, Decl(jsxNamesStartingWithHash.tsx, 14, 5))
+>div : Symbol(JSX.IntrinsicElements.__index, Decl(jsxNamesStartingWithHash.tsx, 2, 33))
+>j:#k : Symbol(j:#k, Decl(jsxNamesStartingWithHash.tsx, 14, 14))
+
+const i = ;
+>i : Symbol(i, Decl(jsxNamesStartingWithHash.tsx, 15, 5))
+>div : Symbol(JSX.IntrinsicElements.__index, Decl(jsxNamesStartingWithHash.tsx, 2, 33))
+> : Symbol((Missing), Decl(jsxNamesStartingWithHash.tsx, 15, 14), Decl(jsxNamesStartingWithHash.tsx, 15, 17))
+> : Symbol((Missing), Decl(jsxNamesStartingWithHash.tsx, 15, 14), Decl(jsxNamesStartingWithHash.tsx, 15, 17))
+>n : Symbol(n, Decl(jsxNamesStartingWithHash.tsx, 15, 23))
+
+const j = <# />;
+>j : Symbol(j, Decl(jsxNamesStartingWithHash.tsx, 16, 5))
+
diff --git a/tsc/testdata/baselines/reference/compiler/jsxNamesStartingWithHash(jsx=preserve).types b/tsc/testdata/baselines/reference/compiler/jsxNamesStartingWithHash(jsx=preserve).types
new file mode 100644
index 0000000000000..a70abd9dd7406
--- /dev/null
+++ b/tsc/testdata/baselines/reference/compiler/jsxNamesStartingWithHash(jsx=preserve).types
@@ -0,0 +1,79 @@
+//// [tests/cases/compiler/jsxNamesStartingWithHash.tsx] ////
+
+=== jsxNamesStartingWithHash.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
+> : any
+> : any
+
+const b = ;
+>b : any
+> : any
+>div : any
+> : true
+
+const c = ;
+>c : any
+> : any
+>div : any
+> : string
+
+const d = ;
+>d : any
+> : any
+>div : any
+>#d:e : true
+> : any
+>e : any
+
+const e = ;
+>e : any
+> : any
+>a : any
+> : any
+
+const f = ;
+>f : any
+> : any
+>a.#g : any
+>a : any
+> : any
+
+const g = <#h:i />;
+>g : any
+><#h:i /> : any
+> : any
+>i : any
+
+const h = ;
+>h : any
+> : any
+>div : any
+>j:#k : true
+>j : any
+> : any
+
+const i = ;
+>i : any
+> : any
+>div : any
+> : true
+> : true
+>n : string
+
+const j = <# />;
+>j : any
+><# /> : any
+> : any
+
diff --git a/tsc/testdata/baselines/reference/compiler/jsxNamesStartingWithHash(jsx=react).errors.txt b/tsc/testdata/baselines/reference/compiler/jsxNamesStartingWithHash(jsx=react).errors.txt
new file mode 100644
index 0000000000000..efd5915050fc0
--- /dev/null
+++ b/tsc/testdata/baselines/reference/compiler/jsxNamesStartingWithHash(jsx=react).errors.txt
@@ -0,0 +1,57 @@
+jsxNamesStartingWithHash.tsx(8,12): error TS1003: Identifier expected.
+jsxNamesStartingWithHash.tsx(8,17): error TS1003: Identifier expected.
+jsxNamesStartingWithHash.tsx(9,16): error TS1003: Identifier expected.
+jsxNamesStartingWithHash.tsx(10,16): error TS1003: Identifier expected.
+jsxNamesStartingWithHash.tsx(11,16): error TS1003: Identifier expected.
+jsxNamesStartingWithHash.tsx(12,14): error TS1003: Identifier expected.
+jsxNamesStartingWithHash.tsx(13,16): error TS1003: Identifier expected.
+jsxNamesStartingWithHash.tsx(14,12): error TS1003: Identifier expected.
+jsxNamesStartingWithHash.tsx(15,18): error TS1003: Identifier expected.
+jsxNamesStartingWithHash.tsx(16,16): error TS1003: Identifier expected.
+jsxNamesStartingWithHash.tsx(16,19): error TS1003: Identifier expected.
+jsxNamesStartingWithHash.tsx(17,12): error TS1127: Invalid character.
+
+
+==== jsxNamesStartingWithHash.tsx (12 errors) ====
+ declare const React: any;
+ declare namespace JSX {
+ interface IntrinsicElements {
+ [name: string]: any;
+ }
+ }
+
+ const a = <#a>#a>;
+ ~~
+!!! error TS1003: Identifier expected.
+ ~~
+!!! error TS1003: Identifier expected.
+ const b = ;
+ ~~
+!!! error TS1003: Identifier expected.
+ const c = ;
+ ~~
+!!! error TS1003: Identifier expected.
+ const d = ;
+ ~~
+!!! error TS1003: Identifier expected.
+ const e = ;
+ ~~
+!!! error TS1003: Identifier expected.
+ const f = ;
+
+!!! error TS1003: Identifier expected.
+ const g = <#h:i />;
+ ~~
+!!! error TS1003: Identifier expected.
+ const h = ;
+ ~~
+!!! error TS1003: Identifier expected.
+ const i = ;
+ ~~
+!!! error TS1003: Identifier expected.
+ ~~
+!!! error TS1003: Identifier expected.
+ const j = <# />;
+ ~
+!!! error TS1127: Invalid character.
+
\ No newline at end of file
diff --git a/tsc/testdata/baselines/reference/compiler/jsxNamesStartingWithHash(jsx=react).js b/tsc/testdata/baselines/reference/compiler/jsxNamesStartingWithHash(jsx=react).js
new file mode 100644
index 0000000000000..7792b25f6e04b
--- /dev/null
+++ b/tsc/testdata/baselines/reference/compiler/jsxNamesStartingWithHash(jsx=react).js
@@ -0,0 +1,34 @@
+//// [tests/cases/compiler/jsxNamesStartingWithHash.tsx] ////
+
+//// [jsxNamesStartingWithHash.tsx]
+declare const React: any;
+declare namespace JSX {
+ interface IntrinsicElements {
+ [name: string]: any;
+ }
+}
+
+const a = <#a>#a>;
+const b = ;
+const c = ;
+const d = ;
+const e = ;
+const f = ;
+const g = <#h:i />;
+const h = ;
+const i = ;
+const j = <# />;
+
+
+//// [jsxNamesStartingWithHash.js]
+"use strict";
+const a = React.createElement(, null);
+const b = React.createElement("div", { "": true });
+const c = React.createElement("div", { "": "" });
+const d = React.createElement("div", { ":e": true });
+const e = React.createElement("a:", null);
+const f = React.createElement(a., null);
+const g = React.createElement(":i", null);
+const h = React.createElement("div", { "j:": true });
+const i = React.createElement("div", { "": true, "": "", n: "" });
+const j = React.createElement(, null);
diff --git a/tsc/testdata/baselines/reference/compiler/jsxNamesStartingWithHash(jsx=react).symbols b/tsc/testdata/baselines/reference/compiler/jsxNamesStartingWithHash(jsx=react).symbols
new file mode 100644
index 0000000000000..f3e62d63b8403
--- /dev/null
+++ b/tsc/testdata/baselines/reference/compiler/jsxNamesStartingWithHash(jsx=react).symbols
@@ -0,0 +1,60 @@
+//// [tests/cases/compiler/jsxNamesStartingWithHash.tsx] ////
+
+=== jsxNamesStartingWithHash.tsx ===
+declare const React: any;
+>React : Symbol(React, Decl(jsxNamesStartingWithHash.tsx, 0, 13))
+
+declare namespace JSX {
+>JSX : Symbol(JSX, Decl(jsxNamesStartingWithHash.tsx, 0, 25))
+
+ interface IntrinsicElements {
+>IntrinsicElements : Symbol(IntrinsicElements, Decl(jsxNamesStartingWithHash.tsx, 1, 23))
+
+ [name: string]: any;
+>name : Symbol(name, Decl(jsxNamesStartingWithHash.tsx, 3, 9))
+ }
+}
+
+const a = <#a>#a>;
+>a : Symbol(a, Decl(jsxNamesStartingWithHash.tsx, 7, 5))
+
+const b = ;
+>b : Symbol(b, Decl(jsxNamesStartingWithHash.tsx, 8, 5))
+>div : Symbol(JSX.IntrinsicElements.__index, Decl(jsxNamesStartingWithHash.tsx, 2, 33))
+> : Symbol((Missing), Decl(jsxNamesStartingWithHash.tsx, 8, 14))
+
+const c = ;
+>c : Symbol(c, Decl(jsxNamesStartingWithHash.tsx, 9, 5))
+>div : Symbol(JSX.IntrinsicElements.__index, Decl(jsxNamesStartingWithHash.tsx, 2, 33))
+> : Symbol((Missing), Decl(jsxNamesStartingWithHash.tsx, 9, 14))
+
+const d = ;
+>d : Symbol(d, Decl(jsxNamesStartingWithHash.tsx, 10, 5))
+>div : Symbol(JSX.IntrinsicElements.__index, Decl(jsxNamesStartingWithHash.tsx, 2, 33))
+>#d:e : Symbol(#d:e, Decl(jsxNamesStartingWithHash.tsx, 10, 14))
+
+const e = ;
+>e : Symbol(e, Decl(jsxNamesStartingWithHash.tsx, 11, 5))
+
+const f = ;
+>f : Symbol(f, Decl(jsxNamesStartingWithHash.tsx, 12, 5))
+>a : Symbol(a, Decl(jsxNamesStartingWithHash.tsx, 7, 5))
+
+const g = <#h:i />;
+>g : Symbol(g, Decl(jsxNamesStartingWithHash.tsx, 13, 5))
+
+const h = ;
+>h : Symbol(h, Decl(jsxNamesStartingWithHash.tsx, 14, 5))
+>div : Symbol(JSX.IntrinsicElements.__index, Decl(jsxNamesStartingWithHash.tsx, 2, 33))
+>j:#k : Symbol(j:#k, Decl(jsxNamesStartingWithHash.tsx, 14, 14))
+
+const i = ;
+>i : Symbol(i, Decl(jsxNamesStartingWithHash.tsx, 15, 5))
+>div : Symbol(JSX.IntrinsicElements.__index, Decl(jsxNamesStartingWithHash.tsx, 2, 33))
+> : Symbol((Missing), Decl(jsxNamesStartingWithHash.tsx, 15, 14), Decl(jsxNamesStartingWithHash.tsx, 15, 17))
+> : Symbol((Missing), Decl(jsxNamesStartingWithHash.tsx, 15, 14), Decl(jsxNamesStartingWithHash.tsx, 15, 17))
+>n : Symbol(n, Decl(jsxNamesStartingWithHash.tsx, 15, 23))
+
+const j = <# />;
+>j : Symbol(j, Decl(jsxNamesStartingWithHash.tsx, 16, 5))
+
diff --git a/tsc/testdata/baselines/reference/compiler/jsxNamesStartingWithHash(jsx=react).types b/tsc/testdata/baselines/reference/compiler/jsxNamesStartingWithHash(jsx=react).types
new file mode 100644
index 0000000000000..a70abd9dd7406
--- /dev/null
+++ b/tsc/testdata/baselines/reference/compiler/jsxNamesStartingWithHash(jsx=react).types
@@ -0,0 +1,79 @@
+//// [tests/cases/compiler/jsxNamesStartingWithHash.tsx] ////
+
+=== jsxNamesStartingWithHash.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
+> : any
+> : any
+
+const b = ;
+>b : any
+> : any
+>div : any
+> : true
+
+const c = ;
+>c : any
+> : any
+>div : any
+> : string
+
+const d = ;
+>d : any
+> : any
+>div : any
+>#d:e : true
+> : any
+>e : any
+
+const e = ;
+>e : any
+> : any
+>a : any
+> : any
+
+const f = ;
+>f : any
+> : any
+>a.#g : any
+>a : any
+> : any
+
+const g = <#h:i />;
+>g : any
+><#h:i /> : any
+> : any
+>i : any
+
+const h = ;
+>h : any
+> : any
+>div : any
+>j:#k : true
+>j : any
+> : any
+
+const i = ;
+>i : any
+> : any
+>div : any
+> : true
+> : true
+>n : string
+
+const j = <# />;
+>j : any
+><# /> : any
+> : any
+
diff --git a/tsc/testdata/tests/cases/compiler/jsxNamesStartingWithHash.tsx b/tsc/testdata/tests/cases/compiler/jsxNamesStartingWithHash.tsx
new file mode 100644
index 0000000000000..c93639dfe642f
--- /dev/null
+++ b/tsc/testdata/tests/cases/compiler/jsxNamesStartingWithHash.tsx
@@ -0,0 +1,20 @@
+// @target: esnext
+// @jsx: preserve,react
+
+declare const React: any;
+declare namespace JSX {
+ interface IntrinsicElements {
+ [name: string]: any;
+ }
+}
+
+const a = <#a>#a>;
+const b = ;
+const c = ;
+const d = ;
+const e = ;
+const f = ;
+const g = <#h:i />;
+const h = ;
+const i = ;
+const j = <# />;