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
16 changes: 12 additions & 4 deletions tsc/internal/parser/parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.parseJsxIdentifier()
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.parseJsxIdentifier()), pos)
}
if isThis {
result := p.factory.NewKeywordExpression(ast.KindThisKeyword)
Expand All @@ -5159,6 +5159,14 @@ func (p *Parser) parseJsxTagName() *ast.Expression {
return tagName
}

func (p *Parser) parseJsxIdentifier() *ast.Node {
if p.token == ast.KindPrivateIdentifier {
p.parseErrorAtCurrentToken(diagnostics.Identifier_expected)
return p.createMissingIdentifier()
Comment on lines +5164 to +5165
}
return p.parseIdentifierNameErrorOnUnicodeEscapeSequence()
}

func (p *Parser) parseJsxAttributes() *ast.Node {
pos := p.nodePos()
return p.finishNode(p.factory.NewJsxAttributes(p.parseList(PCJsxAttributes, (*Parser).parseJsxAttribute)), pos)
Expand All @@ -5184,10 +5192,10 @@ func (p *Parser) parseJsxSpreadAttribute() *ast.Node {
func (p *Parser) parseJsxAttributeName() *ast.Node {
pos := p.nodePos()
p.scanJsxIdentifier()
attrName := p.parseIdentifierNameErrorOnUnicodeEscapeSequence()
attrName := p.parseJsxIdentifier()
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.parseJsxIdentifier()), pos)
}
return attrName
}
Expand Down
3 changes: 3 additions & 0 deletions tsc/internal/scanner/scanner.go
Original file line number Diff line number Diff line change
Expand Up @@ -1370,6 +1370,9 @@ 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 s.token == ast.KindPrivateIdentifier {
return s.token
}
if 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
Expand Down
12 changes: 12 additions & 0 deletions tsc/testdata/tests/cases/compiler/jsxPrivateIdentifier.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
// @target: esnext
// @jsx: react
// @noEmit: true
// @noTypesAndSymbols: true

declare const React: any;

const a = <#a></#a>;
const b = <div #b />;
const c = <div #c="" />;
const d = <div #d:e />;
const e = <a:#f />;
Comment on lines +8 to +12