Skip to content

Use isIdentifierChar instead of regex for toIdentifier#12575

Merged
JLHwung merged 6 commits intobabel:mainfrom
mischnic:12574-toIdentifier-unicode
Dec 31, 2020
Merged

Use isIdentifierChar instead of regex for toIdentifier#12575
JLHwung merged 6 commits intobabel:mainfrom
mischnic:12574-toIdentifier-unicode

Conversation

@mischnic
Copy link
Copy Markdown
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
Copy Markdown
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
Copy Markdown

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

Comment thread packages/babel-types/package.json Outdated
Comment thread packages/babel-types/src/converters/toIdentifier.ts Outdated
Comment thread packages/babel-types/test/converters.js
mischnic and others added 2 commits December 31, 2020 11:17
Co-authored-by: Huáng Jùnliàng <jlhwung@gmail.com>
Comment thread packages/babel-types/test/converters.js Outdated
Copy link
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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