Skip to content

fix(regenerator): throw on using declarations - #18624

Merged
JLHwung merged 7 commits into
mainfrom
jlhwung/fix-regenerator-using-declaration
Nov 17, 2026
Merged

JLHwung merged 7 commits into
mainfrom
jlhwung/fix-regenerator-using-declaration

Conversation

@JLHwung

@JLHwung JLHwung commented Nov 14, 2026

Copy link
Copy Markdown
Contributor
Q                       A
Fixed Issues? See below
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

In this PR we fix an issue reported by Claude Fable: The regenerator transform hoists every variable declaration of the function as a var. A using or await using declaration became a plain assignment, so its resource was never disposed and no error was reported.

In this PR we make this case throw and point to the explicit resource management transform, rather than silently generated incorrect JS codes.

Assisted-by: Claude Fable 5.2

@JLHwung
JLHwung added this pull request to stack #18587 November 14, 2026 19:17
@JLHwung JLHwung added the PR: Bug Fix 🐛 A type of pull request used for our changelog categories label Nov 14, 2026
@JLHwung JLHwung changed the title fix(plugin-transform-regenerator): throw on using declarations fix: throw on using declarations Nov 14, 2026
@babel-bot

babel-bot commented Nov 14, 2026 •

Copy link
Copy Markdown
Collaborator

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

@JLHwung JLHwung changed the title fix: throw on using declarations fix(regenerator): throw on using declarations Nov 14, 2026
@pkg-pr-new

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

Copy link
Copy Markdown

Open in StackBlitz

commit: 7033901

@JLHwung

JLHwung commented Nov 16, 2026

Copy link
Copy Markdown
Contributor Author

@liuxingbaoyu This is a stack PR, could you review the previous ones? Although they are technically not dependent on each other, I use this stack to track a list of similar PRs. This series is to fix issues that an plugin for older language feature does not correctly pass through or throw on the unsupported new syntax.

function varDeclToExpr(path: NodePath, includeIdentifiers: boolean) {
const vdec = path.node;
t.assertVariableDeclaration(vdec);
if (vdec.kind === "using" || vdec.kind === "await using") {

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.

Could we instead list what var kinds are supported? It seems safer and more future-proof.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Good idea. I pushed a new commit and now it will throw if there are var kinds other than var, let and const.

@JLHwung
JLHwung force-pushed the jlhwung/fix-regenerator-using-declaration branch from d39d34e to b65c2b8 Compare November 16, 2026 21:21
export * as ns from "mod" with { type: "json" }

was compiled to an import declaration without the attributes, they are now preserved and cloned if necessary.

Assisted-by: Claude Fable 5.2
export default m from "mod" with { type: "json" }

was compiled to an export declaration without the attributes, they are now cloned.

Assisted-by: Claude Fable 5.2
`{ __proto__() {}, __proto__: p }` is not a duplicate: the second property sets the prototype and does not define a property.

Previously the second property was rewritten to `["__proto__"]: p`, which defines an own property named "__proto__" and leaves the prototype untouched.

Assisted-by: Claude Fable 5.2
…a proto setter

ES5 engines count `__proto__: value` as a data property named "__proto__"
in the duplicate property checks, so `{ get __proto__() {}, __proto__: p }`
is a SyntaxError there even in sloppy mode (tested on V8 3.14 and 3.28).

When an object literal has a `__proto__: value` property, every other
non-computed property named "__proto__" is now made computed, whatever
the order, so that the proto setter keeps setting the prototype.

Assisted-by: Claude Opus 5.5
The regenerator transform hoists every variable declaration of the
function as a `var`. A `using` or `await using` declaration became a
plain assignment, so its resource was never disposed and no error was
reported.

It now throws and points to the explicit resource management
transform, which compiles these declarations before regenerator sees
them when both plugins are enabled.

Assisted-by: Claude Fable 5.2
@JLHwung
JLHwung force-pushed the jlhwung/fix-regenerator-using-declaration branch from b65c2b8 to 7033901 Compare November 16, 2026 21:25
@nicolo-ribaudo
nicolo-ribaudo force-pushed the jlhwung/fix-regenerator-using-declaration branch from 7033901 to 02f73bd Compare November 17, 2026 12:13
Base automatically changed from jlhwung/fix-duplicate-keys-proto-setter to main November 17, 2026 14:54
@JLHwung
JLHwung force-pushed the jlhwung/fix-regenerator-using-declaration branch from 02f73bd to 7033901 Compare November 17, 2026 15:12
@JLHwung
JLHwung added this pull request to the merge queue Nov 17, 2026
Merged via the queue into main with commit bf3497d Nov 17, 2026
83 checks passed
@JLHwung
JLHwung deleted the jlhwung/fix-regenerator-using-declaration branch November 17, 2026 22:48
@babel-bot

Copy link
Copy Markdown
Collaborator

Backported to 7.x in #18650.

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.

4 participants