Skip to content

Commit

Permalink
Remove a loop from importmap checking
Browse files Browse the repository at this point in the history
  • Loading branch information
sirreal committed Dec 19, 2024
1 parent 5eb5dec commit 7a6c553
Showing 1 changed file with 13 additions and 14 deletions.
27 changes: 13 additions & 14 deletions src/wp-includes/class-wp-script-modules.php
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,10 @@ public function print_import_map() {
*/
private function get_import_map(): array {
global $wp_scripts;
$classic_script_module_dependencies = array();

$imports = array();

$classic_script_dependencies = array();
if ( $wp_scripts instanceof WP_Scripts ) {
foreach ( $wp_scripts->registered as $dependency ) {
$handle = $dependency->handle;
Expand All @@ -297,19 +300,18 @@ private function get_import_map(): array {
if ( ! $module_deps ) {
continue;
}
array_push( $classic_script_module_dependencies, ...$module_deps );
foreach ( $module_deps as $id ) {
$src = $this->get_src( $id );
if ( null === $src ) {
continue;
}
$imports[ $id ] = $src;
$classic_script_dependencies[] = $id;
}
}
}

$imports = array();
foreach ( $this->get_dependencies( array_merge( $classic_script_module_dependencies, array_keys( $this->get_marked_for_enqueue() ) ) ) as $id => $script_module ) {
$src = $this->get_src( $id );
if ( null === $src ) {
continue;
}
$imports[ $id ] = $src;
}
foreach ( $classic_script_module_dependencies as $id ) {
foreach ( $this->get_dependencies( array_merge( $classic_script_dependencies, array_keys( $this->get_marked_for_enqueue() ) ) ) as $id => $script_module ) {
$src = $this->get_src( $id );
if ( null === $src ) {
continue;
Expand Down Expand Up @@ -356,9 +358,6 @@ private function get_dependencies( array $ids, array $import_types = array( 'sta
return array_reduce(
$ids,
function ( $dependency_script_modules, $id ) use ( $import_types ) {
if ( ! isset( $this->registered[ $id ]['dependencies'] ) ) {
return $dependency_script_modules;
}
$dependencies = array();
foreach ( $this->registered[ $id ]['dependencies'] as $dependency ) {
if (
Expand Down

0 comments on commit 7a6c553

Please sign in to comment.