Created
July 25, 2020 14:58
-
-
Save randallb/745dd7cdd638f0e1018e3875641b542c to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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("client", ["https://jspm.dev/[email protected]"], function (exports_1, context_1) { | |
"use strict"; | |
var react_16_13_1_1; | |
var __moduleName = context_1 && context_1.id; | |
return { | |
setters: [ | |
function (react_16_13_1_1_1) { | |
react_16_13_1_1 = react_16_13_1_1_1; | |
} | |
], | |
execute: function () { | |
console.log(document.body, react_16_13_1_1.default); | |
} | |
}; | |
}); | |
__instantiate("client", false); | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// @deno-types=https://deno.land/x/types/react/v16.13.1/react.d.ts | |
import React from "https://jspm.dev/[email protected]"; | |
console.log(document.body, React); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const [diagnostics, text] = await Deno.bundle('./client.tsx'); | |
console.log(text); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment