Skip to content

Disallow private identifiers in JSX tag and attribute names (#65396) - #65423

Closed
Mar Mejia (mechazod) wants to merge 1 commit into
microsoft:mainfrom
mechazod:fix/jsx-disallow-hash-identifier
Closed

Mar Mejia (mechazod) wants to merge 1 commit into
microsoft:mainfrom
mechazod:fix/jsx-disallow-hash-identifier

Conversation

@mechazod

Copy link
Copy Markdown

Fixes #65396

Description

In TSX, JSX tag and attribute names starting with # (e.g. <#a></#a>, <div #b />, <div #c="" />, <div #d:e />, <a:#f />) were parsed without a syntax error because ScanJsxIdentifier treated KindPrivateIdentifier under tokenIsIdentifierOrKeyword and converted it into an ordinary identifier, deferring detection to downstream type-checking or missing errors when run with --noCheck.
This change:

  1. Prevents ScanJsxIdentifier from converting KindPrivateIdentifier into regular JSX identifiers.
  2. Disallows private identifiers in parseJsxTagName and parseJsxAttributeName (including namespaced names) by reporting TS1003: Identifier expected. and returning a missing identifier.
  3. Adds test cases covering JSX tag and attribute names starting with #.

@github-project-automation github-project-automation Bot moved this to Not started in PR Backlog Nov 10, 2026
@typescript-automation typescript-automation Bot added the For Backlog Bug PRs that fix a backlog bug label Nov 10, 2026

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟡 Changes recommended

JSX private identifiers remain unconsumed, causing an infinite parser loop and growing memory usage, and the new test is missing its expected diagnostic baseline.

2 open issues
What changed in this PR

This PR addresses #65396 by rejecting private identifiers in JSX tag and attribute names during parsing, so invalid names produce syntax errors even with --noCheck.

Changes:

  • Prevents the scanner from converting private identifiers into ordinary JSX identifiers.
  • Adds parser checks for tag and attribute names, including namespaced names.
  • Adds regression cases for JSX names beginning with #.
File Description
tsc/​testdata/​tests/​cases/​compiler/​jsxPrivateIdentifier.tsx Adds invalid JSX tag and attribute cases.
tsc/​internal/​scanner/​scanner.go Preserves private-identifier tokens during JSX scanning.
tsc/​internal/​parser/​parser.go Adds JSX identifier validation and syntax diagnostics.

Review effort: Balanced

Comment on lines +5164 to +5165
p.parseErrorAtCurrentToken(diagnostics.Identifier_expected)
return p.createMissingIdentifier()
Comment on lines +8 to +12
const a = <#a></#a>;
const b = <div #b />;
const c = <div #c="" />;
const d = <div #d:e />;
const e = <a:#f />;
@RyanCavanaugh

Copy link
Copy Markdown
Member

This isn't quite right

@github-project-automation github-project-automation Bot moved this from Not started to Done in PR Backlog Nov 10, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

For Backlog Bug PRs that fix a backlog bug

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

JSX tag and attribute names starting with # are accepted without a syntax error

3 participants