Skip to content

Conversation

nicolo-ribaudo
Copy link
Member

@nicolo-ribaudo nicolo-ribaudo commented Apr 12, 2025

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?
License MIT

Ignore the === PR STARTS HERE === commit, it's just wrong. All commits are relevant :)

This PR splits the regeneratorRuntime helper into multiple helpers, so that only the necessary ones are loaded. There are now multiple "entry points":

  • regenerator, always used
  • regeneratorKeys, only used when there is a yield inside a for-in
  • regeneratorAsyncGen, only used for async function* () and async function () (when transpiling them through regenerator)
  • regeneratorAsync, only used for async function () (when transpiling them through regenerator)

There are a bunch of new internal helpers, I added a @internal marker to not expose them as part of the public @babel/runtime API.

These are the size differences, when using inline helpers and only @babel/plugin-transform-regenerator, after giving the output to Terser:

CodeBefore (bytes)After (bytes)Size difference
export function* fn() {
  yield "abc";
  yield* "def";
}
61655019-19%
export async function fn() {
  await "abc";
}
61355738-6%
export async function* fn() {
  await "abc";
  yield "abc";
  yield* "def";
}
62245708-8%
export function* fn() {
  for (var k in o) yield k;
}
62205233-16%

@nicolo-ribaudo nicolo-ribaudo changed the title Add test for current behavior Split regeneratorRuntime into multiple helpers Apr 12, 2025
@nicolo-ribaudo nicolo-ribaudo added the PR: Output optimization 🔬 A type of pull request used for our changelog categories label Apr 12, 2025
@babel-bot
Copy link
Collaborator

babel-bot commented Apr 12, 2025

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

@nicolo-ribaudo
Copy link
Member Author

I still need to figure out the e2e failure, but this is ready for review.

@nicolo-ribaudo nicolo-ribaudo marked this pull request as ready for review April 14, 2025 22:01
if (helpers.isInternal(name)) {
throw new Error("Cannot use internal helper " + name);
}
return this.#addHelper(name);
Copy link
Contributor

Choose a reason for hiding this comment

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

Since this file will be compiled to Node.js 6, can we turn on the privateFieldsAsProperties assumption in the build config?

Copy link
Member Author

Choose a reason for hiding this comment

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

I'm using privateFieldsAsSymbols instead, just to avoid potential conflicts.

@nicolo-ribaudo
Copy link
Member Author

nicolo-ribaudo commented Apr 17, 2025

Oh the e2e tests are catching an existing bug: compiling private fields with Babel 7.0.0 and a newer version of the plugin does not work, because the plugin assumes that classPrivateMethodGet is always available (while it's only available starting from 7.1.6).

I'll just avoid using # in this PR.

Copy link
Member

Choose a reason for hiding this comment

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

I should probably write something to remove the useless files in this directory.

Copy link
Member

@liuxingbaoyu liuxingbaoyu left a comment

Choose a reason for hiding this comment

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

Great work!

_regenerator _tryCatch _regeneratorValues _regeneratorDefineIM _regeneratorDefine
_regeneratorAsync _regeneratorAsyncGen _regeneratorAsyncIterator _awaitAsyncGenerator _OverloadYield _regenerator _tryCatch _regeneratorValues _regeneratorDefineIM _regeneratorDefine
_regeneratorAsyncGen _regeneratorAsyncIterator _awaitAsyncGenerator _OverloadYield _regenerator _tryCatch _regeneratorValues _regeneratorDefineIM _regeneratorDefine
_regeneratorKeys _regenerator _tryCatch _regeneratorValues _regeneratorDefineIM _regeneratorDefine

These are helpers used in all four examples, do you mind if I merge some of it in a subsequent PR to make the output cleaner and mangle the function names better?
Also can you merge it into a new branch? I'd like to take this opportunity to improve context a bit. :)

@nicolo-ribaudo nicolo-ribaudo changed the base branch from main to regenerator-refactor April 18, 2025 17:26
@nicolo-ribaudo nicolo-ribaudo merged commit 50fa1b7 into babel:regenerator-refactor Apr 18, 2025
55 checks passed
@nicolo-ribaudo nicolo-ribaudo deleted the regenerator-split branch April 18, 2025 17:27
@nicolo-ribaudo
Copy link
Member Author

Done, in regenerator-refactor 👍

nicolo-ribaudo added a commit to nicolo-ribaudo/babel that referenced this pull request May 27, 2025
@github-actions github-actions bot added the outdated A closed issue/PR that is archived due to age. Recommended to make a new issue label Jul 19, 2025
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jul 19, 2025
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: Output optimization 🔬 A type of pull request used for our changelog categories
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants