Repository navigation
Open
Labels
BugA bug in TypeScriptA bug in TypeScriptDomain: JSX/TSXRelates to the JSX parser and emitterRelates to the JSX parser and emitter
Milestone
Description
🔎 Search Terms
jsx private identifier, jsx tag name hash, jsx attribute name hash, jsx identifier expected, invalid jsx emit
🕗 Version & Regression Information
- This is the behavior in every version I tried (6.0.3, 7.0.2, and nightly 7.1.0-dev.20261108.1), and I reviewed the FAQ for entries about JSX
⏯ Playground Link
💻 Code
declare const React: any;
declare namespace JSX {
interface IntrinsicElements {
[name: string]: any;
}
}
const a = <#a></#a>;
// only TS2304 from the checker
const b = <div #b />;
// no error
const c = <div #c="" />;
// no error
const d = <div #d:e />;
// no error
const e = <a:#f />;
// no errorWith "jsx": "react".
🙁 Actual behavior
JSX tag names and attribute names starting with # are parsed as ordinary identifiers, and no syntax error is reported:
<#a></#a>only reportsTS2304: Cannot find name '#a'.from the checker. WithnoCheck, or in tools that only use syntactic diagnostics, nothing is reported.#b,#c,#d:e, anda:#fin tag and attribute names are accepted with no error at all.
The emitted JavaScript is also invalid:
const a = React.createElement(#a, null);
const b = React.createElement("div", { "#b": true });🙂 Expected behavior
A syntax error, as with <a.#g /> (TS1003: Identifier expected.). # is not a valid character in a JSXIdentifier, and Babel and oxc both reject these inputs.
Additional information about the issue
tokenIsIdentifierOrKeyword (token >= KindIdentifier) also matches KindPrivateIdentifier, so ScanJsxIdentifier and parseIdentifierNameErrorOnUnicodeEscapeSequence treat #a as a regular identifier. <a.#g /> errors only because parseRightSideOfDot checks for private identifiers first.
Reacted by Copilot
Metadata
Metadata
Labels
BugA bug in TypeScriptA bug in TypeScriptDomain: JSX/TSXRelates to the JSX parser and emitterRelates to the JSX parser and emitter
Activity