Repository navigation
Disallow private identifiers in JSX tag and attribute names (#65396) - #65423
Closed
Mar Mejia (mechazod) wants to merge 1 commit into
Closed
Mar Mejia (mechazod) wants to merge 1 commit into
Mar Mejia (mechazod) wants to merge 1 commit into
Conversation
Contributor
There was a problem hiding this comment.
🟡 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 />; |
Member
|
This isn't quite right |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.


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 becauseScanJsxIdentifiertreatedKindPrivateIdentifierundertokenIsIdentifierOrKeywordand converted it into an ordinary identifier, deferring detection to downstream type-checking or missing errors when run with--noCheck.This change:
ScanJsxIdentifierfrom convertingKindPrivateIdentifierinto regular JSX identifiers.parseJsxTagNameandparseJsxAttributeName(including namespaced names) by reportingTS1003: Identifier expected.and returning a missing identifier.#.