refactor: Shrink validator identifier size#18084
Merged
nicolo-ribaudo merged 8 commits intoJun 30, 2026
Merged
Conversation
Collaborator
|
Build successful! You can test your changes in the REPL here: https://babeljs.io/repl/build/61807 |
Contributor
There was a problem hiding this comment.
Pull request overview
This PR refactors @babel/helper-validator-identifier to reduce identifier validation data/regex size by leveraging Node’s built-in Unicode property escapes (Unicode 16 in the minimum supported Node for Babel 8), while introducing a separate browser implementation to avoid bundle bloat in Babel Standalone.
Changes:
- Replace large generated identifier data JSON usage with generated
identifier-regex.tsusing\p{ID_Start}/\p{ID_Continue}plus a small “post-Unicode-16” delta. - Add a browser-specific implementation (
identifier-browser.ts+identifier-regex-browser.ts) and run the shared identifier-name test suite against it. - Update packaging/config to route internal exports via
package.json#imports(#identifier) and adjust ignore/prettier config accordingly.
Reviewed changes
Copilot reviewed 17 out of 18 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
| yarn.lock | Adds regenerate/typings and updates Unicode package versions used for regex generation. |
| scripts/generators/npm-ignore.ts | Stops ignoring now-removed data/ for this package. |
| packages/babel-helper-validator-identifier/test/identifier.spec.js | Refactors tests to reuse shared test helper. |
| packages/babel-helper-validator-identifier/test/identifier-browser.skip-bundled.js | Adds test coverage for the browser implementation (skipped in publish-bundle runs). |
| packages/babel-helper-validator-identifier/test/helpers/describe-is-identifier-name-tests.js | Introduces shared test suite used by both implementations. |
| packages/babel-helper-validator-identifier/src/index.ts | Re-exports identifier helpers via #identifier import mapping. |
| packages/babel-helper-validator-identifier/src/identifier.ts | Switches to new generated regex module and uses fromCodePoint for supplementary checks. |
| packages/babel-helper-validator-identifier/src/identifier-regex.ts | New generated Node-oriented regex + supplementary delta data. |
| packages/babel-helper-validator-identifier/src/identifier-regex-browser.ts | New generated browser-oriented regex/data (no \p{…} usage). |
| packages/babel-helper-validator-identifier/src/identifier-browser.ts | New browser implementation mirroring the previous data-driven logic. |
| packages/babel-helper-validator-identifier/scripts/generate-identifier-regex.ts | Reworks generator to use Unicode ranges + regenerate, and emit new generated modules. |
| packages/babel-helper-validator-identifier/package.json | Adds imports mapping for #identifier and new devDependencies. |
| packages/babel-helper-validator-identifier/data/supplementary-identifier-start.json | Removed (logic moved to generated TS modules). |
| packages/babel-helper-validator-identifier/data/supplementary-identifier-continue.json | Removed (logic moved to generated TS modules). |
| packages/babel-helper-validator-identifier/data/bmp-identifier-start.json | Removed (logic moved to generated TS modules). |
| packages/babel-helper-validator-identifier/data/bmp-identifier-continue.json | Removed (logic moved to generated TS modules). |
| packages/babel-helper-validator-identifier/.npmignore | Stops excluding data/ (directory removed). |
| .prettierignore | Stops excluding this package’s removed data/ directory. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
|
commit: |
nicolo-ribaudo
approved these changes
Jun 29, 2026
liuxingbaoyu
approved these changes
Jun 29, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This PR can be reviewed by commits.
In this PR we simplify the big regex we used when validating the identifier name, based on the fact that Node.js 22.18.0, the minimum Node.js version supported by Babel 8, supports Unicode 16.0. The regex is now simplified to
Ditto for the
ID_Continuebinary property.The previous implementation is still kept for Babel-standalone because the transpiled output of
\p{ID_Start}will further bloat the bundle size, therefore we introduce anidentifier-browserimplementation for Babel standalone and also run the unit test against it./cc @fisker