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

Use isIdentifierChar instead of regex for toIdentifier #12575

Merged
merged 6 commits into from Dec 31, 2020

Conversation

mischnic
Copy link
Contributor

@mischnic mischnic commented Dec 30, 2020

Q                       A
Fixed Issues? Fixes #12574
Patch: Bug Fix? 👍
Major: Breaking Change?
Minor: New Feature?
Tests Added + Pass? Yes
Documentation PR Link
Any Dependency Changes? Only internal
License MIT

Non ASCII-chars that are still valid in an identifier were previously removed (so valid identifiers were turned into _). Use isIdentifierChar instead as suggested in #12574 (comment)

@babel-bot
Copy link
Collaborator

babel-bot commented Dec 30, 2020

Build successful! You can test your changes in the REPL here: https://babeljs.io/repl/build/36641/

@codesandbox-ci
Copy link

codesandbox-ci bot commented Dec 30, 2020

This pull request is automatically built and testable in CodeSandbox.

To see build info of the built libraries, click here or the icon next to each commit SHA.

Latest deployment of this branch, based on commit bdc6b36:

Sandbox Source
babel-repl-custom-plugin Configuration
babel-plugin-multi-config Configuration

mischnic and others added 2 commits December 31, 2020 11:17
Co-authored-by: Huáng Jùnliàng <jlhwung@gmail.com>
Copy link
Member

@nicolo-ribaudo nicolo-ribaudo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you add a test with a name whose first character is a valid identifier char, but not a valid identifier start?

@mischnic
Copy link
Contributor Author

@nicolo-ribaudo I've added expect(t.toIdentifier("1bc")).toBe("bc");. I hope that's what you had in mind?

@nicolo-ribaudo
Copy link
Member

I was thinking more about something non in the ASCII range, like ҇ (\u0487) which is a valid identifier character but it cannot be the first one.

expect(t.toIdentifier("\u0487a")).toBe(...)

Copy link
Member

@nicolo-ribaudo nicolo-ribaudo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

@existentialism existentialism added the PR: Bug Fix 🐛 A type of pull request used for our changelog categories label Dec 31, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
outdated A closed issue/PR that is archived due to age. Recommended to make a new issue PR: Bug Fix 🐛 A type of pull request used for our changelog categories
Projects
None yet
Development

Successfully merging this pull request may close these issues.

@babel/types toIdentifier: naming collision with non-ASCII characters
6 participants