GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — fix(regenerator): support destructuring catch parameters by JLHwung · Pull Request #18732 · babel/babel

Conversation

@JLHwung

@JLHwung JLHwung commented Nov 25, 2026 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Contributor
Q                       A
Fixed Issues? regenerator transform drops the catch param pattern (REPL)
Patch: Bug Fix? Yes
Major: Breaking Change?
Minor: New Feature?
Tests Added + Pass? Yes
Documentation PR Link
Any Dependency Changes?
Need backport? No
License MIT

When a try statement containing a yield had a pattern as its catch parameter, the pattern was dropped: the exception was assigned to a temporary variable and the bindings of the pattern were never created, so their references silently resolved to outer variables.

Given the input

function *f() {
  try {
    throw [1];
    yield 0;
  } catch ([e]) {
    console.log(e);
  }
}
f().next(0);

The output throws e is not defined:

var _marked = /*#__PURE__*/_regenerator().m(f);
function f() {
  var _t;
  return _regenerator().w(function (_context) {
    while (1) switch (_context.p = _context.n) {
      case 0:
        _context.p = 0;
        throw [1];
      case 1:
        _context.n = 3;
        break;
      case 2:
        _context.p = 2;
        _t = _context.v;
        console.log(e);
      case 3:
        return _context.a(2);
    }
  }, _marked, null, [[0, 2]]);
}
f().next(0);

In this PR we pass through catch patterns when possible, unless there is yield or await directly nested in the catch param, which is very rare. In those case we will give up the pass-through and delegate to the @babel/plugin-transform-destructuring transform to handle.


Update: currently merging is blocked by #18617.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@JLHwung
JLHwung added this pull request to stack #18587 November 25, 2026 22:04
@JLHwung JLHwung added PR: Bug Fix 🐛 A type of pull request used for our changelog categories 7.x: needs backport labels Nov 25, 2026
@babel-bot

babel-bot commented Nov 25, 2026 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Collaborator

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

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@JLHwung JLHwung mentioned this pull request Nov 25, 2026
fix(traverse): rename parameter defaults of functions that redeclare the name #18730
Open
@pkg-pr-new

pkg-pr-new Bot commented Nov 25, 2026 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown

Open in StackBlitz

commit: b0a9799

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

liuxingbaoyu
liuxingbaoyu reviewed Nov 26, 2026
View reviewed changes

@liuxingbaoyu liuxingbaoyu left a comment

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

There is a regression here.

function* g() {
  var x = 10;
  try { throw 2; }
  catch (x) { var x = 3; yield x; }
  yield x;
}
console.log([...g()]);

If only regenerator is enabled, its output will fail silently.

function* g() {
  for (var i = 1; i <= 2; i++) {
    try {
      throw { x: i };
    } catch ({ x }) {
      yield () => x;
    }
  }
}

const [first, second] = [...g()];
console.log(first(), second());

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

JLHwung reacted with heart emoji
All reactions
  • ❤️ 1 reaction
@JLHwung

JLHwung commented Nov 26, 2026 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Contributor Author

There is a regression here.

function* g() {
  var x = 10;
  try { throw 2; }
  catch (x) { var x = 3; yield x; }
  yield x;
}
console.log([...g()]);

If only regenerator is enabled, its output will fail silently.

function* g() {
  for (var i = 1; i <= 2; i++) {
    try {
      throw { x: i };
    } catch ({ x }) {
      yield () => x;
    }
  }
}

const [first, second] = [...g()];
console.log(first(), second());

Thank you for the report, this regression has been fixed on #18617, please review that PR. I can not reproduce this issue when rebasing this PR on top of #18617. The main branch is not affected merely because the previous catchParamVisitor matches by name rather than the binding in this PR.

For the time being I will mark this PR as do-not-merge until #18617 is landed.

liuxingbaoyu reacted with heart emoji
All reactions
  • ❤️ 1 reaction

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@JLHwung JLHwung added the ⚠️ Do not merge label Nov 26, 2026
@JLHwung
JLHwung requested a review from liuxingbaoyu November 26, 2026 01:35
@nicolo-ribaudo
nicolo-ribaudo force-pushed the jlhwung/fix-regenerator-catch-pattern branch from f356e11 to d693fca Compare November 27, 2026 23:53
@JLHwung
fix(plugin-transform-regenerator): support destructuring catch parame…
b0a9799
…ters

When a `try` statement containing a yield had a pattern as its `catch`
parameter, the pattern was dropped: the exception was assigned to a
temporary variable and the bindings of the pattern were never created,
so their references silently resolved to outer variables.

The bindings of the catch parameter, an identifier or a pattern, are
now renamed to temporary variables with `scope.rename`, and the
parameter is assigned from the caught exception at the start of the
catch block. A `yield` or `await` inside the pattern still throws and
points to the destructuring transform.

An optional catch binding (`catch {}`) no longer crashes either.

The `this`/`arguments` detection now visits the computed keys of
nested methods and classes, which run with the generator's receiver,
and leaves alone `arguments` references to a binding inside the
generator, such as `catch (arguments)`.

Assisted-by: Claude Opus 5.5
@JLHwung
JLHwung force-pushed the jlhwung/fix-regenerator-catch-pattern branch from d693fca to b0a9799 Compare November 28, 2026 01:40
@JLHwung JLHwung removed the ⚠️ Do not merge label Nov 28, 2026
@JLHwung

JLHwung commented Nov 28, 2026

Copy link
Copy Markdown
Contributor Author

#18617 has been merged, this PR should be ready for review.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

liuxingbaoyu
liuxingbaoyu approved these changes Nov 28, 2026
View reviewed changes

@liuxingbaoyu liuxingbaoyu left a comment

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

These examples seem somewhat extreme, so they do not block this PR.

function* g(obj = { [arguments.length]() {} }) {
  yield Object.keys(obj);
}

console.log(g().next().value);
// main → ["0"]
// PR   → ReferenceError: _args is not defined
function* g() {
  for (let arguments = 1; arguments < 3; arguments++) {
    yield arguments;
  }
}

console.log([...g()]);
// main → [1, 2]
// PR   → [1]
function* g() {
  try {
    yield 1;
  } catch ([__proto__]) {
    yield { __proto__, __proto__: null };
  }
}

console.log(g().next().value);
// main → 1
// PR   → SyntaxError: Duplicate __proto__ fields are not allowed in object literals

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@JLHwung JLHwung mentioned this pull request Nov 28, 2026
fix(regenerator): catch-pattern support review issues #18763
Open
@JLHwung

JLHwung commented Nov 28, 2026

Copy link
Copy Markdown
Contributor Author

@liuxingbaoyu Thank you for the report, they are fixed in #18763.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

This branch has not been deployed

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

Reviewers

@liuxingbaoyu liuxingbaoyu liuxingbaoyu approved these changes

Uh oh!

There was an error while loading. Please reload this page.

Assignees

No one assigned

Labels

7.x: needs backport PR: Bug Fix 🐛 A type of pull request used for our changelog categories

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

Uh oh!

There was an error while loading. Please reload this page.

3 participants

@JLHwung @babel-bot @liuxingbaoyu
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.
You are visitor 01402775 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.