-
Notifications
You must be signed in to change notification settings - Fork 396
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
Allow unicode (Fixes #279) #539
Conversation
…ctly reflect new unicode.ts expected output
Merge the two unicode branches
…th unicode characters, temporarily commented out gothic due to unresolved compatibility issue, updated snapshots
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the contribution, and sorry for the delay!
I'm supportive of this change, but would love to see a simpler implementation. Can we just use https://www.npmjs.com/package/identifierfy (or a similar external library) instead?
cc @mathiasbynens, in case you have a recommendation for the right NPM module to use for coercing strings to valid JS/TS identifiers.
Would the Unicode-aware regex in the latest commit work? That doesn't require any other packages nor the regex-generation scripts. |
I tried using identifierfy but faced some issues when toSafeString was called on the output of toSafeString. Also, it removes more than the minimum in some cases. Ultimately, using identifierfy should work with a few changes to calls of toSafeString |
Great -- want to try doing this? |
I've gotten Identifierfy to work I've had to remove several calls to toSafeString() to prevent double conversion. This should be OK since the parser converts standaloneNames with generateName() |
Closing out stale PRs. |
Fixes #279 and other issues relating to invalid characters in identifiers. It will cover the functionality of #538
This allows any type name that is valid in ES5 by removing invalid characters. Valid characters were determined according to https://mathiasbynens.be/notes/javascript-identifiers.
It uses lodash.template, regenerate, and unicode-11.0.0 to generate the regex in scripts/generate-identifier-regex.ts
It uses code from this gist https://gist.github.com/mathiasbynens/6334847
There is no given license, so I'm not sure if we can use that.
If we can target ES6 or newer, this code can be significantly simplified with Unicode-aware regex.