Microsoft/TypeScript
View on GitHubTypescript supports less valid variable names characters than javascript
Open
#42,452 opened on Jan 22, 2021
BugDomain: ParserHelp Wanted
Description
Bug Report
🔎 Search Terms
unicode invalid character name
🕗 Version & Regression Information
- I specifically tried the zero width space non-joiner. In this particular case at least, the support was lost between versions 3.5.1 and 3.6.3, as shown by the playground.
⏯ Playground Link
Playground link with relevant code
💻 Code
// There is a zero width non-joiner between "x" and "y".
// All versions starting from 3.6.3 think that I am defining a "x" and a "y" variable separately.
// Version 3.5.1 outputs the expected JS code, which is strictly equal to the TS code in this case.
const xy = 42;
🙁 Actual behavior
Not all variable names valid in JS are supported in TS. At least the zero width non-joiner character is not supported. I didn't go on the hunt for all the unsupported characters but clearly TS does not support the full set of supported JS characters anymore.
🙂 Expected behavior
All valid variable names in JS should also be valid variable names in TS. At least when tsconfig is configured to output in an ES version that supports it.
For the record, a wonderful tool exist to test if a variable name is valid in JS: https://mothereff.in/js-variables