jsx icon indicating copy to clipboard operation
jsx copied to clipboard

Normative: disallows UnicodeEscapeSequence

Open Jack-Works opened this issue 3 years ago • 6 comments

For the following code:

import React from 'react'
const x = <video></\u0076ideo>

TypeScript: accept this syntax

TypeScript: reject this syntax after https://github.com/microsoft/TypeScript/pull/48609

Babel: syntax error

swc: syntax error

esbuild: npx esbuild --loader=jsx <<< 'const x = <video></\u0076ideo>'

> <stdin>:1:19: error: Expected identifier but found "\\"
    1 │ const x = <video></\u0076ideo>
      ╵                    ^

Suggested change

Disallows UnicodeEscapeSequence in the JSXIdentifier

Another path

Allow UnicodeEscapeSequence but require them to match in the opening and the closing tag, which means <video></\u0076ideo> is a syntax error (tag mismatch) but <\u0076ideo /> is OK.

Jack-Works avatar Feb 25 '22 04:02 Jack-Works

npx esbuild --loader=jsx <<< 'const x = <video></\u0076ideo>'
 > <stdin>:1:19: error: Expected identifier but found "\\"
    1 │ const x = <video></\u0076ideo>
      ╵                    ^

1 error

wooorm avatar Feb 25 '22 10:02 wooorm

Thanks for catching this! Since implementation already diverged on this, I think we need some discussion and reach a consensus before making this change.

Huxpro avatar Feb 28 '22 22:02 Huxpro

Actually only typescript accepts Unicode escape sequences. Maybe a LGTM from the Typescript team is enough.

Jack-Works avatar Mar 01 '22 01:03 Jack-Works

Happy to disallow this from the TypeScript side

RyanCavanaugh avatar Apr 07 '22 19:04 RyanCavanaugh

hi! Since TypeScript merges https://github.com/microsoft/TypeScript/pull/48609, now this is consistent behavior across the most common transpilers in the ecosystem, that is disallows UnicodeEscapeSequence in JSXIdentifier. I think this PR can be merged now. I don't know who I can ping because Huxpro has left Meta. Maybe @sebmarkbage? Please take a look, thanks!

Jack-Works avatar Aug 10 '23 03:08 Jack-Works

hi! Since TypeScript merges microsoft/TypeScript#48609, now this is consistent behavior across the most common transpilers in the ecosystem, that is disallows UnicodeEscapeSequence in JSXIdentifier. I think this PR can be merged now. I don't know who I can ping because Huxpro has left Meta. Maybe @sebmarkbage? Please take a look, thanks!

Thanks @Jack-Works! @sebmarkbage actually left before me 😂.

I'm supportive of this change. Maybe @poteto can take a look?

Huxpro avatar Oct 25 '23 00:10 Huxpro