From c9ee64ad2e5e05ecbc40eb95faa3a0775ae674b1 Mon Sep 17 00:00:00 2001 From: George Mamadashvili Date: Fri, 7 Feb 2025 13:11:19 +0400 Subject: [PATCH] Exclude Iterator helpers from polyfills (#69070) * Exclude Iterator helpers from polyfills * Use assertEqualSets * Ignore bundled packages Co-authored-by: Mamaduka Co-authored-by: swissspidy --- .../polyfill-exclusions.js | 5 ++ phpunit/script-dependencies-test.php | 48 +++++++++++++++++++ 2 files changed, 53 insertions(+) create mode 100644 phpunit/script-dependencies-test.php diff --git a/packages/babel-preset-default/polyfill-exclusions.js b/packages/babel-preset-default/polyfill-exclusions.js index ca8c045d124146..9d0d18737540cb 100644 --- a/packages/babel-preset-default/polyfill-exclusions.js +++ b/packages/babel-preset-default/polyfill-exclusions.js @@ -28,4 +28,9 @@ module.exports = [ // // @see https://github.com/WordPress/gutenberg/pull/67230 /^es(next)?\.set\./, + // Remove Iterator feature polyfills. + // For the same reasoning as for Set exlusion above, we're excluding all iterator helper polyfills. + // + // @see https://github.com/WordPress/wordpress-develop/pull/8224#issuecomment-2636390007. + /^es(next)?\.iterator\./, ]; diff --git a/phpunit/script-dependencies-test.php b/phpunit/script-dependencies-test.php new file mode 100644 index 00000000000000..66f5c0a7e3dc57 --- /dev/null +++ b/phpunit/script-dependencies-test.php @@ -0,0 +1,48 @@ +registered; + $dependents = array(); + + // Iterate over all registered scripts, finding dependents of the `wp-polyfill` script. + // Based on private `WP_Scripts::get_dependents` method. + foreach ( $registered_scripts as $registered_handle => $args ) { + // Ignore bundled packages, they don't load separate polyfills. + if ( in_array( $registered_handle, $this->bundled_scripts, true ) ) { + continue; + } + + if ( in_array( 'wp-polyfill', $args->deps, true ) ) { + $dependents[] = $registered_handle; + } + } + + // This list should get smaller over time as we remove `wp-polyfill` dependencies. + // If the list update is intentional, please add a comment explaining why. + $expected = array( + 'react', + 'wp-blob', + 'wp-block-editor', + 'wp-block-library', + 'wp-blocks', + 'wp-edit-site', + 'wp-core-data', + 'wp-editor', + 'wp-router', + 'wp-url', + 'wp-widgets', + ); + + $this->assertEqualSets( $expected, $dependents ); + } +}