Skip to content

Commit

Permalink
Exclude Iterator helpers from polyfills
Browse files Browse the repository at this point in the history
  • Loading branch information
Mamaduka committed Feb 6, 2025
1 parent 484ace3 commit a6427a2
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 0 deletions.
5 changes: 5 additions & 0 deletions packages/babel-preset-default/polyfill-exclusions.js
Original file line number Diff line number Diff line change
Expand Up @@ -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\./,
];
45 changes: 45 additions & 0 deletions phpunit/script-dependencies-test.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
<?php

/**
* @group script-dependencies
*/
class Test_Script_Dependencies extends WP_UnitTestCase {
/**
* Tests for accidental `wp-polyfill` script dependents.
*/
public function test_polyfill_dependents() {
$scripts = wp_scripts();
$registered_scripts = $scripts->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 ) {
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 list update intentionally, 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',
'wp-upload-media',
);

sort( $expected, SORT_STRING );
sort( $dependents, SORT_STRING );

$this->assertSame( $expected, $dependents );
}
}

0 comments on commit a6427a2

Please sign in to comment.