Microsoft/TypeScript

Typescript supports less valid variable names characters than javascript

Open

#42,452 opened on 2021年1月22日

GitHub で見る
 (1 comment) (1 reaction) (0 assignees)TypeScript (48,455 stars) (6,726 forks)batch import
BugDomain: ParserHelp Wanted

説明

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 x‌y = 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

コントリビューターガイド