Skip to content

Conversation

Copilot
Copy link
Contributor

@Copilot Copilot AI commented Aug 19, 2025

Iterator helper methods are now part of the ECMAScript 2025 specification and should be included in polyfills by default, without requiring the shippedProposals option to be enabled.

Problem

Previously, code using iterator helpers like x.find() would not include the necessary polyfills unless shippedProposals: true was explicitly set in the preset-env configuration:

// Without shippedProposals: true, this would not include polyfills
x.find(item => item.value > 10);

This behavior was inconsistent with Babel's preset-env, which updated their database to include iterator helpers by default (see babel/babel-polyfills#223).

Solution

Modified the polyfill injection logic in crates/swc_ecma_preset_env/src/corejs3/usage.rs to allow iterator helper modules (esnext.iterator.* and esnext.async-iterator.*) even when shippedProposals is disabled.

The fix adds a special case for iterator helpers:

if !*shipped_proposals && f.starts_with("esnext.") {
    // Iterator helpers are part of ES2025 and should be enabled by default
    if is_iterator_helper(f) {
        // Allow iterator helpers even when shipped_proposals is false
    } else {
        return false;
    }
}

Result

Now iterator helper usage automatically includes the necessary polyfills:

// Input
x.find();

// Output (with automatic polyfill imports)
import "core-js/modules/esnext.async-iterator.find.js";
import "core-js/modules/esnext.iterator.constructor.js";
import "core-js/modules/esnext.iterator.find.js";
x.find();

This works with the standard configuration without requiring shippedProposals: true:

{
  "presets": [
    ["@swc/preset-env", {
      "useBuiltIns": "usage",
      "corejs": "3.45.0",
      "targets": "chrome 80"
    }]
  ]
}

Testing

  • Added test case to verify iterator helpers are included without shippedProposals
  • Verified existing tests continue to pass with no regressions
  • Confirmed behavior matches expected ECMAScript 2025 standard compliance

Fixes #11010


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

Copy link

changeset-bot bot commented Aug 19, 2025

⚠️ No Changeset found

Latest commit: fd5818b

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@CLAassistant
Copy link

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.
You have signed the CLA already but the status is still pending? Let us recheck it.

@Copilot Copilot AI changed the title [WIP] try to fix this issue: @swc-project/swc/issues/11010 fix(preset-env): Include iterator helpers polyfills without shippedProposals Aug 19, 2025
@Copilot Copilot AI requested a review from magic-akari August 19, 2025 11:36
Copilot finished work on behalf of magic-akari August 19, 2025 11:36
@swc-project swc-project locked as resolved and limited conversation to collaborators Sep 18, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Development

Successfully merging this pull request may close these issues.

Iterator helper polyfills should be included even if shippedProposals is not enabled
3 participants