Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
test: pin scoped import-map resolution for dynamic import()
The host names a dynamic import's referrer by script origin - a file://
URL - while scope keys prefix-match the referrer's canonical registry
key. The origin must land on that key space or scoped lookups silently
fall through to top-level imports, which is exactly what happened on iOS
for local referrers. Android's derivation is correct by construction
(the origin routes through CanonicalizeRegistryKey's file:// branch),
but nothing pinned it; now a fixture inside a scoped directory resolves
a bare specifier through import() and the spec asserts the scope's
target wins.
  • Loading branch information
edusperoni committed Aug 20, 2026
commit fe90214acf47a882bd6d6575380516315b482282
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
// Dynamic import must consult the same scope as a static import from this
// file: the host names the referrer by script origin, and that origin must
// canonicalize to the registry key the scope prefixes match against.
export function load() {
return import("ns-scoped-leaf");
}
23 changes: 23 additions & 0 deletions test-app/app/src/main/assets/app/tests/testEsmHttpLoader.js
Original file line number Diff line number Diff line change
Expand Up @@ -356,6 +356,29 @@ describe("HTTP ESM Loader", function () {
reportRejection(error, done);
});
});

it("applies the referrer's scope to dynamic import()", function (done) {
// The host names a dynamic import's referrer by script origin
// (a file:// URL), not by registry key; the origin must land on
// the same canonical key the scope prefixes match, or scoped
// lookups silently fall through to top-level imports.
var insideScope = appRoot + "/esm/scoped/inside/";
var scopes = {};
scopes[insideScope] = { "ns-scoped-leaf": origin + "/esm/graph-leaf.mjs?k=in" };
setMap({
imports: { "ns-scoped-leaf": origin + "/esm/graph-leaf.mjs?k=top" },
scopes: scopes,
});

import("~/esm/scoped/inside/dynamic.mjs").then(function (mod) {
return mod.load();
}).then(function (leafMod) {
expect(leafMod.name).toBe("in");
done();
}).catch(function (error) {
reportRejection(error, done);
});
Comment thread
coderabbitai[bot] marked this conversation as resolved.
});
});

// An imperative API rejects bad input loudly, the way WebIDL does on the
Expand Down