Skip to content

Commit 4524f38

Browse files
committed
[core] only rewrite actual urls for dynamic imports
1 parent 86cdc10 commit 4524f38

File tree

2 files changed

+15
-4
lines changed

2 files changed

+15
-4
lines changed

rewriter/js/src/visitor.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,7 @@ where
185185

186186
fn visit_import_declaration(&mut self, it: &ImportDeclaration<'data>) {
187187
let str = it.source.to_string();
188-
if str.contains(":") || str.starts_with("/") || str.starts_with("./") || str.starts_with("../") {
188+
if str.contains(":") || str.starts_with("/") || str.starts_with(".") || str.starts_with("..") {
189189
self.rewrite_url(&it.source,true);
190190
}
191191
walk::walk_import_declaration(self, it);

src/client/shared/import.ts

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,20 @@ export default function (client: ScramjetClient, self: Self) {
88
self[config.globals.importfn] = function (base: string, url: string) {
99
const resolved = new URL(url, base).href;
1010

11-
return Function(
12-
`return import("${rewriteUrl(resolved, client.meta)}?type=module")`
13-
)();
11+
if (
12+
url.includes(":") ||
13+
url.startsWith("/") ||
14+
url.startsWith(".") ||
15+
url.startsWith("..")
16+
) {
17+
// this is a url
18+
return Function(
19+
`return import("${rewriteUrl(resolved, client.meta)}?type=module")`
20+
)();
21+
} else {
22+
// this is a specifier handled by importmaps
23+
return Function(`return import("${url}")`)();
24+
}
1425
};
1526

1627
self[config.globals.metafn] = function (base: string) {

0 commit comments

Comments
 (0)