Skip to content

Commit 12f1615

Browse files
Yoav Weisschromium-wpt-export-bot
authored andcommitted
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}
1 parent 2e800b1 commit 12f1615

2 files changed

Lines changed: 86 additions & 0 deletions

File tree

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
<!DOCTYPE html>
2+
<html>
3+
<head>
4+
<script src="/resources/testharness.js"></script>
5+
<script src="/resources/testharnessreport.js"></script>
6+
</head>
7+
<body>
8+
<script>
9+
const log = [];
10+
</script>
11+
<!-- First import map with a MORE specific scope -->
12+
<script type="importmap">
13+
{
14+
"scopes": {
15+
"/import-maps/multiple-import-maps/": {
16+
"bar": "/import-maps/resources/log.js?pipe=sub&name=specific"
17+
}
18+
}
19+
}
20+
</script>
21+
<!-- Second import map with a LESS specific scope -->
22+
<script type="importmap">
23+
{
24+
"scopes": {
25+
"/import-maps/": {
26+
"bar": "/import-maps/resources/log.js?pipe=sub&name=general"
27+
}
28+
}
29+
}
30+
</script>
31+
<script type="module">
32+
// This module's base URL is in /import-maps/multiple-import-maps/
33+
// The more specific scope should still be checked first, even though
34+
// it was added in the first import map and the less specific scope
35+
// was added in the second import map.
36+
promise_test(async () => {
37+
await import("bar");
38+
// Should use the more specific scope mapping to "specific", not "general"
39+
assert_array_equals(log, ["log:specific"]);
40+
}, "Scope ordering should be correct regardless of import map insertion order");
41+
</script>
42+
</body>
43+
</html>
44+
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
<!DOCTYPE html>
2+
<html>
3+
<head>
4+
<script src="/resources/testharness.js"></script>
5+
<script src="/resources/testharnessreport.js"></script>
6+
</head>
7+
<body>
8+
<script>
9+
const log = [];
10+
</script>
11+
<!-- First import map with a less specific scope -->
12+
<script type="importmap">
13+
{
14+
"scopes": {
15+
"/import-maps/": {
16+
"bar": "/import-maps/resources/log.js?pipe=sub&name=general"
17+
}
18+
}
19+
}
20+
</script>
21+
<!-- Second import map with a more specific scope -->
22+
<script type="importmap">
23+
{
24+
"scopes": {
25+
"/import-maps/multiple-import-maps/": {
26+
"bar": "/import-maps/resources/log.js?pipe=sub&name=specific"
27+
}
28+
}
29+
}
30+
</script>
31+
<script type="module">
32+
// This module's base URL is in /import-maps/multiple-import-maps/
33+
// The more specific scope should be checked first
34+
promise_test(async () => {
35+
await import("bar");
36+
// Should use the more specific scope mapping to "specific", not "general"
37+
assert_array_equals(log, ["log:specific"]);
38+
}, "More specific scope from second import map should be checked first");
39+
</script>
40+
</body>
41+
</html>
42+

0 commit comments

Comments
 (0)