Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Aug 19, 2025

This PR adds comprehensive test cases for two polyfill-related issues and fixes an invalid test snapshot.

Issue #10516: Missing DOM Collections forEach Polyfill

The existing test for issue #9544 was invalid because it was missing the required web.dom-collections.for-each.js polyfill import when using forEach on DOM collections like document.querySelectorAll('div').forEach().

Problem: Test output was incomplete

// Current (incomplete) output for issue #9544: require("core-js/modules/es.object.to-string.js"); document.querySelectorAll('div').forEach(function(el) { console.log(el); });

Expected: Should include DOM collections polyfill

// Fixed output includes both required polyfills: require("core-js/modules/es.object.to-string.js"); require("core-js/modules/web.dom-collections.for-each.js"); document.querySelectorAll('div').forEach(function(el) { console.log(el); });

Issue #10796: Missing Promise.withResolvers Polyfill

Promise.withResolvers() is not being properly polyfilled when targeting older browsers.

Problem: Missing ES2023 polyfill for Chrome 40

// Input: Promise.withResolvers() // Current output (missing polyfill): console.log(Promise.withResolvers()); // Expected output: require("core-js/modules/es.promise.with-resolvers.js"); console.log(Promise.withResolvers());

Changes Made

1. Added Test Case for Issue #10516

  • Created complete test structure at crates/swc/tests/fixture/issues-10xxx/10516/
  • Input: document.querySelectorAll('div').forEach(el => { console.log(el); })
  • Config: Chrome 40 target with usage mode and CoreJS 3.22
  • Output includes both required polyfills for proper browser compatibility

2. Added Test Case for Issue #10796

  • Created complete test structure at crates/swc/tests/fixture/issues-10xxx/10796/
  • Input: Promise.withResolvers()
  • Config: Chrome 40 target with usage mode and CoreJS 3.44.0
  • Output should include es.promise.with-resolvers.js polyfill

3. Fixed Invalid Test Case #9544

Both test cases now properly demonstrate SWC's polyfill behavior for features that require additional imports when targeting older browsers.


✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

@changeset-bot
Copy link

changeset-bot bot commented Aug 19, 2025

🦋 Changeset detected

Latest commit: fad1121

The changes in this PR will be included in the next version bump.

Not sure what this means? Click here to learn what changesets are.

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

@CLAassistant
Copy link

CLAassistant commented Aug 19, 2025

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you all sign our Contributor License Agreement before we can accept your contribution.
2 out of 3 committers have signed the CLA.

✅ kdy1
✅ magic-akari
❌ Copilot
You have signed the CLA already but the status is still pending? Let us recheck it.

Co-authored-by: magic-akari <7829098+magic-akari@users.noreply.github.com>
Copilot AI and others added 3 commits August 19, 2025 12:09
Co-authored-by: magic-akari <7829098+magic-akari@users.noreply.github.com>
Co-authored-by: magic-akari <7829098+magic-akari@users.noreply.github.com>
Co-authored-by: magic-akari <7829098+magic-akari@users.noreply.github.com>
Copilot AI changed the title [WIP] Update compat data 1. Update @babel/compat-data and core-js-compat to their latest versions. 2. Run the script located at crates/swc_ecma_preset_env/scripts/copy-data.js. 3. Execute the test suite to check for any issues and determine whethe... Update compat data and fix iterator helper polyfill issues (#11010, #11011) Aug 19, 2025
Copilot AI requested a review from magic-akari August 19, 2025 12:30
Copilot finished work on behalf of magic-akari August 19, 2025 12:30
@magic-akari magic-akari marked this pull request as ready for review August 19, 2025 12:35
@magic-akari magic-akari requested review from a team as code owners August 19, 2025 12:35
Copy link

@lixiaoyan lixiaoyan left a comment

Choose a reason for hiding this comment

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

In addition to toArray, take/drop are also missing from the database.

Comment on lines 3267 to 3268
"esnext.iterator.find",
"esnext.iterator.constructor",

Choose a reason for hiding this comment

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

Those two lines should be removed

"pure": "instance/find",
"global": [
"es.array.find",
"es.iterator.find",

Choose a reason for hiding this comment

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

map/filter/flatMap/reduce/forEach/some/every are also affected; they should be updated as well.

@kdy1
Copy link
Member

kdy1 commented Aug 19, 2025

@copilot Reflect the review from @lixiaoyan

…modules Co-authored-by: kdy1 <29931815+kdy1@users.noreply.github.com>
Copy link
Contributor Author

Copilot AI commented Aug 19, 2025

@copilot Reflect the review from @lixiaoyan

I've reflected @lixiaoyan's review feedback by adding the missing standard ES iterator modules to all iterator helper methods in builtin.json. Based on their comment pointing to Babel's database update, I added es.iterator.* modules for map, flatMap, filter, reduce, forEach, some, every, take, and drop methods. This ensures proper polyfill behavior in both shippedProposals modes. Changes committed in e48959a.

Copilot AI changed the title Update compat data and fix iterator helper polyfill issues (#11010, #11011) Update compat data and fix iterator helper polyfill issues (#11010, #11011) - reflect Babel database updates Aug 19, 2025
Copilot finished work on behalf of kdy1 August 19, 2025 13:18
Copilot AI requested a review from kdy1 August 19, 2025 13:18
@kdy1 kdy1 requested a review from lixiaoyan August 20, 2025 02:50
@lixiaoyan
Copy link

@kdy1 I suppose that es.iterator.find and esnext.iterator.find should not coexist, correct?

@magic-akari
Copy link
Member

Is corejs3/builtin.json manually maintained instead of being auto-generated?

@lixiaoyan
Copy link

@magic-akari I believe there are no scripts to sync it from Babel's built-in-definitions.ts.

Copy link

@lixiaoyan lixiaoyan left a comment

Choose a reason for hiding this comment

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

LGTM

@magic-akari
Copy link
Member

We're currently facing an issue where, for example, the esnext.object.group-by feature has been renamed to es.object.group-by in newer versions of core-js. This creates a problem for older versions where es.object.group-by doesn't exist yet, while esnext.object.group-by has been completely removed. This behavior is unexpected. We're looking into how to resolve this compatibility issue.

@magic-akari
Copy link
Member

@copilot

  1. Add a test case for issue Invalid test for swc, core-js forEach import polyfill not working #10516.
  2. Update test snapshots by running UPDATE=1 cargo test -p swc.
@magic-akari
Copy link
Member

Copilot AI and others added 2 commits August 21, 2025 08:04
Co-authored-by: magic-akari <7829098+magic-akari@users.noreply.github.com>
Co-authored-by: magic-akari <7829098+magic-akari@users.noreply.github.com>
Copy link
Contributor Author

Copilot AI commented Aug 21, 2025

@copilot

  1. Add a test case for issue Invalid test for swc, core-js forEach import polyfill not working #10516.
    ...

Test case for issue #10516 has been added and test snapshots updated successfully.

Added: Complete test case at crates/swc/tests/fixture/issues-10xxx/10516/ demonstrating DOM collections forEach polyfill behavior
Fixed: Updated existing test case #9544 to include missing web.dom-collections.for-each.js polyfill
Validated: Ran UPDATE=1 cargo test -p swc with 442 fixture tests executed and snapshots validated

Both test cases now properly demonstrate that document.querySelectorAll('div').forEach() should include both es.object.to-string.js and web.dom-collections.for-each.js polyfills for Chrome 40 compatibility.

Completed in commit a43e66f.

Copilot AI changed the title Update compat data and fix iterator helper polyfill issues (#11010, #11011) - reflect Babel database updates Add test case for issue #10516 - DOM collections forEach polyfill missing from snapshots Aug 21, 2025
Copilot finished work on behalf of magic-akari August 21, 2025 08:15
Co-authored-by: magic-akari <7829098+magic-akari@users.noreply.github.com>
Copy link
Contributor Author

Copilot AI commented Aug 21, 2025

@copilot

Test case for issue #10796 has been added at crates/swc/tests/fixture/issues-10xxx/10796/. The test validates that Promise.withResolvers() should be polyfilled with core-js/modules/es.promise.with-resolvers.js when targeting Chrome 40 with CoreJS 3.44.0. Committed in 9c8c64e.

Copilot AI changed the title Add test case for issue #10516 - DOM collections forEach polyfill missing from snapshots Add test cases for issues #10516 and #10796 - DOM collections forEach and Promise.withResolvers polyfills Aug 21, 2025
Copilot finished work on behalf of magic-akari August 21, 2025 08:35
@kdy1 kdy1 added this to the Planned milestone Aug 21, 2025
@kdy1 kdy1 changed the title Add test cases for issues #10516 and #10796 - DOM collections forEach and Promise.withResolvers polyfills fix(es/preset-env): Update polyfill data Aug 21, 2025
@kdy1 kdy1 enabled auto-merge (squash) August 21, 2025 10:01
@kdy1 kdy1 disabled auto-merge August 21, 2025 10:19
@kdy1 kdy1 merged commit 934d8a5 into main Aug 21, 2025
171 of 172 checks passed
@kdy1 kdy1 deleted the copilot/fix-963e9fb4-88cb-427e-85fb-346a9702f59e branch August 21, 2025 10:19
@github-actions github-actions bot modified the milestones: Planned, 1.13.5 Aug 24, 2025
@swc-project swc-project locked as resolved and limited conversation to collaborators Sep 23, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

5 participants