summaryrefslogtreecommitdiff
path: root/deno_typescript/system_loader.js
diff options
context:
space:
mode:
authorKitson Kelly <me@kitsonkelly.com>2020-02-27 03:59:33 +1100
committerGitHub <noreply@github.com>2020-02-26 17:59:33 +0100
commit671f0b83be5cf9f9b6b1d667d41fd7779896a21a (patch)
treea53bf8ed33b3921260170ab1ace40e3a77374661 /deno_typescript/system_loader.js
parent942e67c00b8ebdf6671fc8bb2e6c78c3ad8b3ff8 (diff)
Bundles can be sync or async based on top level await (#4124)
Previously, bundles always utilised top level await, even if the bundled modules didn't require top level await. Now, analysis of the bundle is done and if none of the bundled modules are asynchronously executed, then the bundle as a whole will be synchronously executed. Fixes #4055 Fixes #4123
Diffstat (limited to 'deno_typescript/system_loader.js')
-rw-r--r--deno_typescript/system_loader.js72
1 files changed, 43 insertions, 29 deletions
diff --git a/deno_typescript/system_loader.js b/deno_typescript/system_loader.js
index c1365f6c8..18a08107e 100644
--- a/deno_typescript/system_loader.js
+++ b/deno_typescript/system_loader.js
@@ -2,20 +2,16 @@
// This is a specialised implementation of a System module loader.
-// eslint-disable-next-line @typescript-eslint/no-unused-vars
-let System;
-let __inst;
+// @ts-nocheck
+/* eslint-disable */
+
+let System, __inst, __inst_s;
(() => {
const mMap = new Map();
System = {
- register(id, deps, f) {
- mMap.set(id, {
- id,
- deps,
- f,
- exp: {}
- });
+ register(id, d, f) {
+ mMap.set(id, { id, d, f, exp: {} });
}
};
@@ -28,11 +24,10 @@ let __inst;
};
};
- const gE = data => {
- const { exp } = data;
- return (id, value) => {
- const values = typeof id === "string" ? { [id]: value } : id;
- for (const [id, value] of Object.entries(values)) {
+ const gE = ({ exp }) => {
+ return (id, v) => {
+ const vs = typeof id === "string" ? { [id]: v } : id;
+ for (const [id, value] of Object.entries(vs)) {
Object.defineProperty(exp, id, {
value,
writable: true,
@@ -47,39 +42,58 @@ let __inst;
const enq = ids => {
for (const id of ids) {
if (!iQ.includes(id)) {
- const { deps } = mMap.get(id);
+ const { d } = mMap.get(id);
iQ.push(id);
- enq(deps);
+ enq(d);
}
}
};
- const dr = async main => {
+ const gRQ = main => {
const rQ = [];
let id;
while ((id = iQ.pop())) {
- const m = mMap.get(id);
- const { f } = m;
- if (!f) {
- return;
- }
- rQ.push([m.deps, f(gE(m), gC(m, id === main))]);
- m.f = undefined;
+ const m = mMap.get(id),
+ { f } = m;
+ if (!f) return;
+ rQ.push([m.d, f(gE(m), gC(m, id === main))]);
+ delete m.f;
}
+ return rQ;
+ };
+
+ const dr = async main => {
+ const rQ = gRQ(main);
let r;
while ((r = rQ.shift())) {
- const [deps, { execute, setters }] = r;
- for (let i = 0; i < deps.length; i++) setters[i](mMap.get(deps[i])?.exp);
+ const [d, { execute, setters }] = r;
+ for (let i = 0; i < d.length; i++) setters[i](mMap.get(d[i])?.exp);
const e = execute();
if (e) await e;
}
};
+ const dr_s = main => {
+ const rQ = gRQ(main);
+ let r;
+ while ((r = rQ.shift())) {
+ const [d, { execute, setters }] = r;
+ for (let i = 0; i < d.length; i++) setters[i](mMap.get(d[i])?.exp);
+ execute();
+ }
+ };
+
__inst = async id => {
- System = undefined;
- __inst = undefined;
+ System = __inst = __inst_s = undefined;
enq([id]);
await dr(id);
return mMap.get(id)?.exp;
};
+
+ __inst_s = id => {
+ System = __inst = __inst_s = undefined;
+ enq([id]);
+ dr_s(id);
+ return mMap.get(id)?.exp;
+ };
})();