Skip to content

fix: preserve comments following async function wrappers - #18644

Merged
JLHwung merged 5 commits into
babel:mainfrom
leoliu012:fix-16454
Nov 19, 2026
Merged

JLHwung merged 5 commits into
babel:mainfrom
leoliu012:fix-16454

Conversation

@lilyqin7

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

This PR fixes comment placement when an async function declaration is split into the public wrapper (a) and the generated implementation (_a). One comment is attached as both a trailing comment on the preceding export and a leading comment on the following export. Previously, the comment would remain attached to the respective functions in the respective orders while the generated implementation (_a) was inserted after the outer export function. This fix moves trailing comments from the original statement onto _a, the generated function. This preserves a following function's documentation comment above that function.

Before this change, Babel wrote the comment for b before the generated _a implementation:

export function a() {
  return _a.apply(this, arguments);
}

/** Documentation for function b. */
function _a() {
  // ...
}

export function b() {
  return 42;
}

After this change, _a is written before b's documentation comment:

export function a() {
  return _a.apply(this, arguments);
}

function _a() {
  // ...
}

/** Documentation for function b. */
export function b() {
  return 42;
}

This PR also adds a regression fixture to the @babel/plugin-transform-async-to-generator suite. It defines an input and expected output, which is compared against Babel's generated output.

@babel-bot

babel-bot commented Nov 17, 2026 •

Copy link
Copy Markdown
Collaborator

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

@pkg-pr-new

pkg-pr-new Bot commented Nov 17, 2026 •

Copy link
Copy Markdown

Open in StackBlitz

commit: 523bd4a

@JLHwung JLHwung left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Thank you for opening your first PR. Please remove comments from the src, the implementation is straightforward.

Per our AI policy, please disclose in the commit message if this PR is AI-assisted.

@lilyqin7

Copy link
Copy Markdown
Contributor Author

@JLHwung Comments removed!

@JLHwung
JLHwung added this pull request to the merge queue Nov 19, 2026
@JLHwung
JLHwung removed this pull request from the merge queue due to a manual request Nov 19, 2026
@JLHwung
JLHwung added this pull request to the merge queue Nov 19, 2026
@JLHwung JLHwung added 7.x: needs backport PR: Bug Fix 🐛 A type of pull request used for our changelog categories labels Nov 19, 2026
@github-merge-queue
github-merge-queue Bot removed this pull request from the merge queue due to failed status checks Nov 19, 2026
@JLHwung
JLHwung added this pull request to the merge queue Nov 19, 2026
Merged via the queue into babel:main with commit 71fbaa4 Nov 19, 2026
54 checks passed
@babel-bot

Copy link
Copy Markdown
Collaborator

Backported to 7.x in #18667.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

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.

[Bug]: asyncToGenerator insert after comments of the next function

5 participants