Skip to content

Instantly share code, notes, and snippets.

@matt-allan
Created September 11, 2020 16:58
Show Gist options
  • Save matt-allan/bcaba41630d2c640a868fe0c7eb4d73b to your computer and use it in GitHub Desktop.
Save matt-allan/bcaba41630d2c640a868fe0c7eb4d73b to your computer and use it in GitHub Desktop.
// Copyright 2018-2020 the Deno authors. All rights reserved. MIT license.
// This is a specialised implementation of a System module loader.
"use strict";
// @ts-nocheck
/* eslint-disable */
let System, __instantiate;
(() => {
const r = new Map();
System = {
register(id, d, f) {
r.set(id, { d, f, exp: {} });
},
};
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: (m) => dI(m, id),
meta: { url: id, main },
};
}
function gE(exp) {
return (id, v) => {
v = typeof id === "string" ? { [id]: v } : id;
for (const [id, value] of Object.entries(v)) {
Object.defineProperty(exp, id, {
value,
writable: true,
enumerable: true,
});
}
};
}
function rF(main) {
for (const [id, m] of r.entries()) {
const { f, exp } = m;
const { execute: e, setters: s } = f(gE(exp), gC(id, id === main));
delete m.f;
m.e = e;
m.s = s;
}
}
async function gExpA(id) {
if (!r.has(id)) return;
const m = r.get(id);
if (m.s) {
const { d, e, s } = m;
delete m.s;
delete m.e;
for (let i = 0; i < s.length; i++) s[i](await gExpA(d[i]));
const r = e();
if (r) await r;
}
return m.exp;
}
function gExp(id) {
if (!r.has(id)) return;
const m = r.get(id);
if (m.s) {
const { d, e, s } = m;
delete m.s;
delete m.e;
for (let i = 0; i < s.length; i++) s[i](gExp(d[i]));
e();
}
return m.exp;
}
__instantiate = (m, a) => {
System = __instantiate = undefined;
rF(m);
return a ? gExpA(m) : gExp(m);
};
})();
System.register("app", ["https://cdn.skypack.dev/preact@^10.4.4?dts"], function (exports_1, context_1) {
"use strict";
var preact__10_4_4_dts_1;
var __moduleName = context_1 && context_1.id;
return {
setters: [
function (preact__10_4_4_dts_1_1) {
preact__10_4_4_dts_1 = preact__10_4_4_dts_1_1;
}
],
execute: function () {
preact__10_4_4_dts_1.render(preact__10_4_4_dts_1.h('div', null, 'hello world'), document.body);
}
};
});
__instantiate("app", false);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment