diff options
author | Kitson Kelly <me@kitsonkelly.com> | 2020-06-17 23:13:02 +1000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-06-17 15:13:02 +0200 |
commit | 75bb9dbdfc7f8b4e8d17978808ae575e61843aef (patch) | |
tree | 570b8a537d13a72957afcfad1cdd339f13ccd93d /deno_typescript/system_loader.js | |
parent | e88d72f101e773728c27306a3639589c1350e4ed (diff) |
Deno.bundle supports targets < ES2017. (#6328)
This commit provides a "system_loader_es5.js" bundle loader which will be added
to the bundle when the target is < ES2017, which is the minimum target syntax
required for "system_loader.js".
Supports #5913 (via Deno.bundle()) with a couple caveats:
* Allowing "deno bundle" to take a different target is not supported, as we
specifically ignore "target" when passed in a TypeScript config file. This is
because deno bundle is really intended to generate bundles that work in Deno.
It is an unintentional side effect that some bundles are loadable in browsers.
* While a target of "es3" will be accepted, the module loader will still only be
compatible with ES5 or later. Realistically no one should be expecting bundles
generated by Deno to be used on IE8 and prior, and there is just too much
"baggage" to support that at this point.
Diffstat (limited to 'deno_typescript/system_loader.js')
-rw-r--r-- | deno_typescript/system_loader.js | 41 |
1 files changed, 14 insertions, 27 deletions
diff --git a/deno_typescript/system_loader.js b/deno_typescript/system_loader.js index fdf1fa872..55f88e8c7 100644 --- a/deno_typescript/system_loader.js +++ b/deno_typescript/system_loader.js @@ -6,17 +6,14 @@ // @ts-nocheck /* eslint-disable */ -let System, __instantiateAsync, __instantiate; - +let System, __instantiate; (() => { - const r = new Map(); - + const r = Object.create(null); System = { register(id, d, f) { - r.set(id, { d, f, exp: {} }); + r[id] = { d, f, exp: {} }; }, }; - async function dI(mid, src) { let id = mid.replace(/\.\w+$/i, ""); if (id.includes("./")) { @@ -33,9 +30,8 @@ let System, __instantiateAsync, __instantiate; if (s < sa.length) oa.push(...sa.slice(s)); id = oa.reverse().join("/"); } - return r.has(id) ? gExpA(id) : import(mid); + return id in r ? gExpA(id) : import(mid); } - function gC(id, main) { return { id, @@ -43,7 +39,6 @@ let System, __instantiateAsync, __instantiate; meta: { url: id, main }, }; } - function gE(exp) { return (id, v) => { v = typeof id === "string" ? { [id]: v } : id; @@ -56,9 +51,10 @@ let System, __instantiateAsync, __instantiate; } }; } - function rF(main) { - for (const [id, m] of r.entries()) { + let m; + for (const id in r) { + m = r[id]; const { f, exp } = m; const { execute: e, setters: s } = f(gE(exp), gC(id, id === main)); delete m.f; @@ -66,10 +62,9 @@ let System, __instantiateAsync, __instantiate; m.s = s; } } - async function gExpA(id) { - if (!r.has(id)) return; - const m = r.get(id); + if (!(id in r)) return; + const m = r[id]; if (m.s) { const { d, e, s } = m; delete m.s; @@ -80,10 +75,9 @@ let System, __instantiateAsync, __instantiate; } return m.exp; } - function gExp(id) { - if (!r.has(id)) return; - const m = r.get(id); + if (!(id in r)) return; + const m = r[id]; if (m.s) { const { d, e, s } = m; delete m.s; @@ -93,16 +87,9 @@ let System, __instantiateAsync, __instantiate; } return m.exp; } - - __instantiateAsync = async (m) => { - System = __instantiateAsync = __instantiate = undefined; - rF(m); - return gExpA(m); - }; - - __instantiate = (m) => { - System = __instantiateAsync = __instantiate = undefined; + __instantiate = (m, a) => { + System = __instantiate = undefined; rF(m); - return gExp(m); + return a ? gExpA(m) : gExp(m); }; })(); |