Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Insonsistent parsing of JsxIdentifier #32701

Closed
ajafff opened this issue Aug 4, 2019 · 4 comments · Fixed by #32716
Closed

Insonsistent parsing of JsxIdentifier #32701

ajafff opened this issue Aug 4, 2019 · 4 comments · Fixed by #32716
Labels
Bug A bug in TypeScript Fix Available A PR has been opened for this issue
Milestone

Comments

@ajafff
Copy link
Contributor

ajafff commented Aug 4, 2019

TypeScript Version: 3.6.0-dev.20190804

Search Terms:

Code

let a = <\u0061></a>; // works
let ab = <\u0061-b></a-b>; // works
let ac = <a-\u0063></a-c>; // reports mismatching closing tag

Expected behavior:

Consistent parsing of escaped characters in JSX Identifiers.
I don't know the JSX spec, so I cannot tell whether all should be valid or all should be invalid

Actual behavior:

parseJsxIdentifier is only responsible for everything after the first dash. It wasn't changed to support unicode characters. Therefore the regular Identifier parsing allows escaped characters in the first part.

Related Issues:

#32096 forgot to change parseJsxIdentifier. cc @weswigham

@ajafff
Copy link
Contributor Author

ajafff commented Aug 4, 2019

Babel doesn't seem to parse escaped characters in JSX at all.

@weswigham
Copy link
Member

JSXIdentifier is still defined in terms of the core IdentifierStart/IdentifierPart, which include Unicode escape sequences, so I suppose they should all work - Babel's wrong here, I suppose.

@RyanCavanaugh RyanCavanaugh added the Bug A bug in TypeScript label Aug 5, 2019
@RyanCavanaugh RyanCavanaugh added this to the Backlog milestone Aug 5, 2019
@RyanCavanaugh
Copy link
Member

If the fix for this turns out to be at all nontrivial, this is going to Won't Fix unless there's a compelling scenario here I've overlooked 😅

let a = <\u0061></a>;

Do we know if this is supposed to be legal?

@weswigham
Copy link
Member

Do we know if this is supposed to be legal?

With the spec AST as written, yes.

JSXIdentifier is:

IdentifierStart
JSXIdentifier IdentifierPart
JSXIdentifier NO WHITESPACE OR COMMENT -

while ES6+ defined IdentifierStart and IdentifierPart as:

IdentifierStart::
    UnicodeIDStart
    $
    _
    \UnicodeEscapeSequence

IdentifierPart::
    UnicodeIDContinue
    $
    \UnicodeEscapeSequence
    <ZWNJ>
    <ZWJ>

so escape sequences being valid in jsx just falls out from the definitions.

@weswigham weswigham added the Fix Available A PR has been opened for this issue label Aug 5, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug A bug in TypeScript Fix Available A PR has been opened for this issue
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants