commit 89f76a6a3e4e9e8fac9efe1fcea4b09dc2fe4b4d
parent 3a6c918558a5a91abd386e03448122531b5e5829
Author: Yoav Weiss <yoavweiss@chromium.org>
Date: Wed, 26 Nov 2025 09:01:03 +0000
Bug 2002283 [wpt PR 56261] - Fix up scope ordering with multiple import maps, a=testonly
Automatic update from web-platform-tests
Fix up scope ordering with multiple import maps
As a follow up from https://chromium-review.googlesource.com/c/chromium/src/+/7117300
this CL fixes the ordering of scopes when multiple import maps are
involved. It does that by ensuring that scopes_vector_ is sorted after
a merge.
Bug: 433490539, 406357273, 453147451
Change-Id: I80a3bfacbbf3eebe34e392215f85d4869bb8ea8a
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/7201449
Reviewed-by: Kouhei Ueno <kouhei@chromium.org>
Commit-Queue: Yoav Weiss (@Shopify) <yoavweiss@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1549715}
--
wpt-commits: 12f16152045fb4531a5e7c0cd1e4fcd62bd9cb0b
wpt-pr: 56261
Diffstat:
2 files changed, 86 insertions(+), 0 deletions(-)
diff --git a/testing/web-platform/tests/import-maps/multiple-import-maps/scope-ordering-reverse.html b/testing/web-platform/tests/import-maps/multiple-import-maps/scope-ordering-reverse.html
@@ -0,0 +1,44 @@
+<!DOCTYPE html>
+<html>
+<head>
+ <script src="/resources/testharness.js"></script>
+ <script src="/resources/testharnessreport.js"></script>
+</head>
+<body>
+<script>
+const log = [];
+</script>
+<!-- First import map with a MORE specific scope -->
+<script type="importmap">
+{
+ "scopes": {
+ "/import-maps/multiple-import-maps/": {
+ "bar": "/import-maps/resources/log.js?pipe=sub&name=specific"
+ }
+ }
+}
+</script>
+<!-- Second import map with a LESS specific scope -->
+<script type="importmap">
+{
+ "scopes": {
+ "/import-maps/": {
+ "bar": "/import-maps/resources/log.js?pipe=sub&name=general"
+ }
+ }
+}
+</script>
+<script type="module">
+// This module's base URL is in /import-maps/multiple-import-maps/
+// The more specific scope should still be checked first, even though
+// it was added in the first import map and the less specific scope
+// was added in the second import map.
+promise_test(async () => {
+ await import("bar");
+ // Should use the more specific scope mapping to "specific", not "general"
+ assert_array_equals(log, ["log:specific"]);
+}, "Scope ordering should be correct regardless of import map insertion order");
+</script>
+</body>
+</html>
+
diff --git a/testing/web-platform/tests/import-maps/multiple-import-maps/scope-ordering.html b/testing/web-platform/tests/import-maps/multiple-import-maps/scope-ordering.html
@@ -0,0 +1,42 @@
+<!DOCTYPE html>
+<html>
+<head>
+ <script src="/resources/testharness.js"></script>
+ <script src="/resources/testharnessreport.js"></script>
+</head>
+<body>
+<script>
+const log = [];
+</script>
+<!-- First import map with a less specific scope -->
+<script type="importmap">
+{
+ "scopes": {
+ "/import-maps/": {
+ "bar": "/import-maps/resources/log.js?pipe=sub&name=general"
+ }
+ }
+}
+</script>
+<!-- Second import map with a more specific scope -->
+<script type="importmap">
+{
+ "scopes": {
+ "/import-maps/multiple-import-maps/": {
+ "bar": "/import-maps/resources/log.js?pipe=sub&name=specific"
+ }
+ }
+}
+</script>
+<script type="module">
+// This module's base URL is in /import-maps/multiple-import-maps/
+// The more specific scope should be checked first
+promise_test(async () => {
+ await import("bar");
+ // Should use the more specific scope mapping to "specific", not "general"
+ assert_array_equals(log, ["log:specific"]);
+}, "More specific scope from second import map should be checked first");
+</script>
+</body>
+</html>
+