summaryrefslogtreecommitdiff
path: root/deno_typescript/system_loader.js
diff options
context:
space:
mode:
authorKitson Kelly <me@kitsonkelly.com>2020-04-02 14:14:30 +1100
committerGitHub <noreply@github.com>2020-04-01 23:14:30 -0400
commit2e24385c487d5471aceae7d7e7de9da4c7d87064 (patch)
tree8337f0df8c3ba8078bd7112ff61f5e082025f664 /deno_typescript/system_loader.js
parent2ff8012dccf648916212918c69f6b5d7b6dedc56 (diff)
Support dynamic import in bundles. (#4561)
Diffstat (limited to 'deno_typescript/system_loader.js')
-rw-r--r--deno_typescript/system_loader.js21
1 files changed, 20 insertions, 1 deletions
diff --git a/deno_typescript/system_loader.js b/deno_typescript/system_loader.js
index b5b10af48..0004d055d 100644
--- a/deno_typescript/system_loader.js
+++ b/deno_typescript/system_loader.js
@@ -15,10 +15,29 @@ let System, __instantiateAsync, __instantiate;
},
};
+ async function dI(mid, src) {
+ let id = mid.replace(/\.\w+$/i, "");
+ if (id.includes("./")) {
+ const [o, ...ia] = id.split("/").reverse(),
+ [, ...sa] = src.split("/").reverse(),
+ oa = [o];
+ let s = 0,
+ i;
+ while ((i = ia.shift())) {
+ if (i === "..") s++;
+ else if (i === ".") break;
+ else oa.push(i);
+ }
+ if (s < sa.length) oa.push(...sa.slice(s));
+ id = oa.reverse().join("/");
+ }
+ return r.has(id) ? gExpA(id) : import(mid);
+ }
+
function gC(id, main) {
return {
id,
- import: async (id) => r.get(id)?.exp,
+ import: (m) => dI(m, id),
meta: { url: id, main },
};
}