Skip to content

async generators use Chrome 55 threshold (async/await's), should be 63 #11958

Description

@HandSonic

Describe the bug

SWC env does not downlevel async generators for Chrome 60 target

Summary

SWC's env compat-data reports Chrome 60 as supporting async generator syntax (async function*). Async generators actually shipped in Chrome 63 (Dec 2017). As a result, env with targets: { chrome: '60' } leaves async function* syntax untouched in the output, which will throw a SyntaxError in Chrome 60–62.

Reproduction

import { transform } from '@swc/core'

const result = await transform(
  'export default async function*() { yield 1 }',
  {
    env: {
      targets: { chrome: '60' },
      mode: 'usage',
      coreJs: '3.49.0',
      shippedProposals: true,
    },
  },
)

console.log(result.code)

Expected output

Async generator syntax downleveled to regenerator-based helpers (similar to what @babel/preset-env produces for the same target).

Actual output

import "core-js/modules/es.promise.js";
export default async function*() {
    yield 1;
}

The async function* syntax is preserved unchanged. The only polyfill injected is es.promise.js — no regenerator-runtime, no async-iterator helpers.

Environment

  • @swc/core: 1.15.41
  • Node.js: v22.x
  • OS: Windows 11

Affected syntax

All async generator forms survive untransformed:

export default async function*() { yield 1 }
const x = async function*() { yield 1 }
async function* gen() { yield 1 }
const probe = !!(async function*(){})

Reference: Babel's behavior

@babel/preset-env with the same target correctly downlevels async generators for Chrome 60:

require('@babel/core').transformSync('export default async function*() { yield 1 }', {
  presets: [['@babel/preset-env', { targets: { chrome: '60' }, shippedProposals: true }]],
})

Babel's compat-data identifies Chrome 63 as the async-generator threshold (@babel/compat-data), so it applies @babel/plugin-proposal-async-generator-functions for Chrome 60.

Likely cause

The async-generator compat-data entry for Chrome in SWC's compat table appears to list Chrome 60 as supporting async generators, rather than Chrome 63.

Actual shipping versions (per MDN / Chromestatus):

  • Chrome 63 (Dec 2017): async iterators support — async function*, for await...of

Related

  • SWC compat-data source: @swc/core's compat table
  • Babel reference: @babel/compat-data correctly marks Chrome 63 as the threshold

Input code

import { transform } from '@swc/core'

const result = await transform(
  'export default async function*() { yield 1 }',
  {
    env: {
      targets: { chrome: '60' },
      mode: 'usage',
      coreJs: '3.49.0',
      shippedProposals: true,
    },
  },
)

console.log(result.code)

Config

Link to the code that reproduces this issue

https://play.swc.rs/?version=1.15.41&code=H4sIAAAAAAAAA0VPQWrDMBC8G%2FyHuckuwU1pKSRQ6LmnfkHIa0cga81q3TQE%2F71SUzeXYZmd2Zn108yiuELFxjSwTFgxCE8w7%2BnsHh0LmbqqK8cxKYTSEhRvsGfr9W5q6gow9P17rKfBFpVNl%2BgwLNGp5%2FjQtDnm4in0eMJqdsVyLQBQ%2FDpuM6BWRtKUGbhTrkJHmNe9wbrbFBP3hVySHcn8s6XrR7aZ5%2B7l0O3vi3Ty80z9p%2FDMyYYsUVnob327WrDd%2FuRAXeCxuX3buZzW%2FgARS0MmKQEAAA%3D%3D&config=H4sIAAAAAAAAA1WPMQ7DIAxFd06BPHdth96hh0DUiUjBIEzUoih3LyGQNhv%2B%2F5knL0JKmFjDXS7lWYagImM85pJwpqQ%2BJQHUTrGOJiS49HbirRqUZazRujeQVBwx1S2%2BNhys94wdb5kzZIb8L9TehYjMZ3BDFY0WzzrRlOD8c65lOyTlgLv%2BBj%2Boy46PwfCjb8JML%2FJvArF%2BATHGky4ZAQAA

SWC Info output

Operating System:
    Platform: win32
    Arch: x64
    Machine Type: x86_64
    Version: Windows 11 Pro for Workstations
    CPU: (20 cores)
        Models: 12th Gen Intel(R) Core(TM) i7-12700KF

Binaries:
    Node: 22.22.2
    npm: N/A
    Yarn: N/A
    pnpm: N/A

Relevant Packages:
    @swc/core: N/A
    @swc/helpers: N/A
    @swc/types: N/A


SWC Config:
    output: N/A
    .swcrc path: N/A

Next.js info:
    output: N/A

Expected behavior

Async generator syntax downleveled to regenerator-based helpers (similar to what @babel/preset-env produces for the same target).

Actual behavior

export default async function*() { yield 1 }
const x = async function*() { yield 1 }
async function* gen() { yield 1 }
const probe = !!(async function*(){})

Version

1.15.41

Additional context

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-bugConfirmedConfirmed that this is a bug or an issue that should be fixed

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions