Skip to content

fix(regenerator): compile yield in object spreads and computed keys - #18709

Merged
JLHwung merged 1 commit into
mainfrom
jlhwung/fix-regenerator-object-members
Nov 25, 2026
Merged

JLHwung merged 1 commit into
mainfrom
jlhwung/fix-regenerator-object-members

Conversation

@JLHwung

@JLHwung JLHwung commented Nov 24, 2026 •

Copy link
Copy Markdown
Contributor
Q                       A
Fixed Issues? Compile yield in spread element and avoid shorthand __proto__ being expanded in regenerator
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

Currently, the regenerator on main transforms

function* f(__proto__) {
  return {
    ...(yield "spread"),
    [yield "computed"]: "value",
    __proto__
  }
}

to

function f(__proto__) {
  var _t;
  return _regenerator().w(function (_context) {
    while (1) switch (_context.n) {
      case 0:
        _t = __proto__;
        return _context.a(2, {
          ...(yield "spread"), // yield is not lowered 
          [yield "computed"]: "value", // yield is not lowered 
          __proto__: _t, // becomes a __proto__ setter
        });
    }
  }, _marked);
}

because the regenerator transform is not aware of the spread element, computed key and proto setter.

All three issues are fixed on this PR since the implementation stays together.

To clarify, this PR does not lower the object spread element, which should be handled by the object-rest-spread transform.

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

babel-bot commented Nov 24, 2026 •

Copy link
Copy Markdown
Collaborator

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

@pkg-pr-new

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

Copy link
Copy Markdown

Open in StackBlitz

commit: d392e56

Base automatically changed from jlhwung/fix-regenerator-logical-assignment to main November 24, 2026 16:01
Only the values of object properties were compiled. A `yield` in a
spread element or in a computed key was left as is in the generated
function, where it is an identifier in sloppy mode: the generator did
not suspend anymore, and read a variable named `yield`.

A shorthand `{ __proto__ }` next to a yield was also printed as
`__proto__: _t`, which sets the prototype instead of defining a
property.

Assisted-by: Claude Fable 5.2
@JLHwung
JLHwung force-pushed the jlhwung/fix-regenerator-object-members branch from 3460925 to d392e56 Compare November 24, 2026 16:01
@JLHwung
JLHwung added this pull request to the merge queue Nov 25, 2026
Merged via the queue into main with commit 68cfec5 Nov 25, 2026
41 checks passed
@JLHwung
JLHwung deleted the jlhwung/fix-regenerator-object-members branch November 25, 2026 15:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

7.x: needs backport 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.

3 participants