Skip to content

fix(regenerator): handle destructuring hoist crash in async (#17517)#17877

Open
Vikash9546 wants to merge 1 commit intobabel:mainfrom
Vikash9546:fix-regenerator-hoist-patterns-17517
Open

fix(regenerator): handle destructuring hoist crash in async (#17517)#17877
Vikash9546 wants to merge 1 commit intobabel:mainfrom
Vikash9546:fix-regenerator-hoist-patterns-17517

Conversation

@Vikash9546
Copy link
Copy Markdown

@Vikash9546 Vikash9546 commented Mar 17, 2026

Problem

When running @babel/plugin-transform-async-to-generator followed by @babel/plugin-transform-regenerator, async code containing untransformed destructuring can crash with:

  • Property name expected type of string but got undefined

Repro from #17517:

const testA = async () => {
  return async () => {
    const { resData, config } = {}
    console.log('a', resData)
  }
}

Cause

Regenerator's hoist pass assumed every VariableDeclarator has an Identifier id, and used dec.id.name when collecting vars. With destructuring, dec.id is a pattern so name is undefined, triggering the @babel/types invariant.

Solution

Collect binding identifiers via getBindingIdentifiers(dec.id) instead of assuming Identifier, so patterns are supported and the transform no longer crashes.

Tests

  • Added a regression test covering the repro (packages/babel-plugin-transform-regenerator/test/regression-17517.js).

Fixes #17517

…7517)

Regenerator's hoist pass assumed VariableDeclarator ids are always Identifiers.
When async-to-generator runs without transform-destructuring, destructuring
patterns can reach regenerator and crash while generating hoisted vars.

Made-with: Cursor
@babel-bot
Copy link
Copy Markdown
Collaborator

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

@@ -0,0 +1,34 @@
import { transformSync } from "@babel/core";
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.

In general we embrace fixture-based test cases for plugin behaviour: See https://github.com/babel/babel/blob/main/CONTRIBUTING.md#writing-tests

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Error: Property name expected type of string but got undefined when using async functions with @babel/plugin-transform-regenerator

3 participants