Skip to content

fix(regenerator): dispatch pending jump after finally to outer finally blocks - #18557

Merged
nicolo-ribaudo merged 2 commits into
babel:mainfrom
hoanle0126:fix/regenerator-nested-finally-jump-18530
Nov 10, 2026
Merged

nicolo-ribaudo merged 2 commits into
babel:mainfrom
hoanle0126:fix/regenerator-nested-finally-jump-18530

Conversation

@hoanle0126

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

When an inner finally block finished a pending Jump (break or continue), invoke assigned ctx.n = arg directly without dispatching the jump through Context_dispatchExceptionOrFinishOrAbrupt, which skipped outer enclosing finally blocks.

@babel-bot

babel-bot commented Nov 9, 2026 •

Copy link
Copy Markdown
Collaborator

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

@pkg-pr-new

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

Copy link
Copy Markdown

Open in StackBlitz

commit: d4322fc

@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.

Could you add a new test case? (Both input and exec), for example,

  try {
    while (true) {
      try {
        try {
          break;
        } finally {
          log("a");
        }
      } finally {
        log("b");
      }
    }
    log("afterLoop");
    yield 1;
  } finally {
    log("outer");
  }

this PR should already pass this case. However, such case will ensure that any future change will not run the outer finally too early.

@@ -0,0 +1,37 @@
const breakEvents = [];

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.

Please add an input.js derived from the exec.js test, you can remove the assertions so we are sure the output is not changed, only the helper codes are updated.

@JLHwung JLHwung added PR: Bug Fix 🐛 A type of pull request used for our changelog categories 7.x: needs backport labels Nov 9, 2026
@hoanle0126

Copy link
Copy Markdown
Contributor Author

Thanks for the review @JLHwung! I've added input.js (along with the generated output.js snapshot) and included the outer try/finally test case in both input.js and exec.js in d4322fc.

@nicolo-ribaudo nicolo-ribaudo left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thanks!

@nicolo-ribaudo
nicolo-ribaudo added this pull request to the merge queue Nov 10, 2026
Merged via the queue into babel:main with commit 2fede97 Nov 10, 2026
45 checks passed
@babel-bot

Copy link
Copy Markdown
Collaborator

Backported to 7.x in #18569.

JLHwung pushed a commit to JLHwung/babel that referenced this pull request Nov 10, 2026
…y blocks (babel#18557)

* fix(regenerator): dispatch pending jump after finally to outer finally blocks

* test(regenerator): add input/output snapshot and outer finally test case
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.

Regenerator: break/continue out of two nested try … finally in a generator skips the outer finally

4 participants