Skip to content

Mangle top level names in helpers - #18397

Merged
nicolo-ribaudo merged 4 commits into
babel:mainfrom
nicolo-ribaudo:mangle-top-level-names-in-helpers
Oct 23, 2026
Merged

nicolo-ribaudo merged 4 commits into
babel:mainfrom
nicolo-ribaudo:mangle-top-level-names-in-helpers

Conversation

@nicolo-ribaudo

Copy link
Copy Markdown
Member
Q                       A
Fixed Issues? Fixes #1, Fixes #2
Patch: Bug Fix?
Major: Breaking Change?
Minor: New Feature?
Tests Added + Pass? Yes
Documentation PR Link
Any Dependency Changes?
Need backport? No
License MIT

@nicolo-ribaudo nicolo-ribaudo added the PR: Internal 🏠 A type of pull request used for our changelog categories label Oct 23, 2026
@babel-bot

babel-bot commented Oct 23, 2026 •

Copy link
Copy Markdown
Collaborator

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

@pkg-pr-new

pkg-pr-new Bot commented Oct 23, 2026 •

Copy link
Copy Markdown

Open in StackBlitz

commit: c99d2ff

@nicolo-ribaudo
nicolo-ribaudo force-pushed the mangle-top-level-names-in-helpers branch from 1a8505d to 409ca08 Compare October 23, 2026 13:45
@JLHwung

JLHwung commented Oct 23, 2026 •

Copy link
Copy Markdown
Contributor

Although typically we wrap each helper within a closure so mangling top level names is safe, we do have a build-external-helper-cli where we concat each helper within a single scope, and thus it would be broken by this PR due to shared top level names, such as e used by both classPrivateFieldLooseKey and jsx.

We could let buildHelpers somehow learn the map from original names to mangled names, but that would require an interface change to the build-external-helper cli.

@nicolo-ribaudo

Copy link
Copy Markdown
Member Author

That seems like a risk with the current setup already, since nothing prevents us from re-using the same top level names. What if I made babel-external-helpers prefix non-exported variable names with the default export name?

@nicolo-ribaudo

Copy link
Copy Markdown
Member Author

Actually, when injecting names we can just check if they conflict with the previous ones. I pushed a fix.

Comment thread packages/babel-core/test/api.js Resolved
JLHwung
JLHwung approved these changes Oct 23, 2026 •
@nicolo-ribaudo
nicolo-ribaudo merged commit 0b1ff08 into babel:main Oct 23, 2026
56 checks passed
@nicolo-ribaudo
nicolo-ribaudo deleted the mangle-top-level-names-in-helpers branch October 23, 2026 21:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

PR: Internal 🏠 A type of pull request used for our changelog categories

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants