forked from denoland/deno
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Moves to using a minimal System loader for bundles generated by Deno. TypeScript in 3.8 will be able to output TLA for modules, and the loader is written to take advantage of that as soon as we update Deno to TS 3.8. System also allows us to support `import.meta` and provide more ESM aligned assignment of exports, as well as there is better handling of circular imports. The loader is also very terse versus to try to save overhead. Also, fixed an issue where abstract classes were not being rexported. Fixes denoland#2553 Fixes denoland#3559 Fixes denoland#3751 Fixes denoland#3825 Refs denoland#3301
- Loading branch information
Showing
7 changed files
with
112 additions
and
25 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,22 +1,24 @@ | ||
[WILDCARD] | ||
let define; | ||
let System; | ||
let __inst; | ||
[WILDCARD] | ||
let instantiate; | ||
[WILDCARD] | ||
(function() { | ||
(() => { | ||
[WILDCARD] | ||
})(); | ||
|
||
define("print_hello", ["require", "exports"], function (require, exports) { | ||
System.register("print_hello", [], function (exports_1, context_1) { | ||
[WILDCARD] | ||
}); | ||
define("mod1", ["require", "exports", "subdir2/mod2"], function (require, exports, mod2_ts_1) { | ||
System.register("subdir2/mod2", ["print_hello"], function (exports_2, context_2) { | ||
[WILDCARD] | ||
}); | ||
System.register("mod1", ["subdir2/mod2"], function (exports_3, context_3) { | ||
[WILDCARD] | ||
}); | ||
|
||
const __rootExports = instantiate("mod1"); | ||
export const returnsHi = __rootExports["returnsHi"]; | ||
export const returnsFoo2 = __rootExports["returnsFoo2"]; | ||
export const printHello3 = __rootExports["printHello3"]; | ||
export const throwsError = __rootExports["throwsError"]; | ||
|
||
const __exp = await __inst("mod1"); | ||
export const returnsHi = __exp["returnsHi"]; | ||
export const returnsFoo2 = __exp["returnsFoo2"]; | ||
export const printHello3 = __exp["printHello3"]; | ||
export const throwsError = __exp["throwsError"]; | ||
[WILDCARD] |
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
// Copyright 2018-2020 the Deno authors. All rights reserved. MIT license. | ||
|
||
// This is a specialised implementation of a System module loader. | ||
|
||
let System; | ||
let __inst; | ||
|
||
(() => { | ||
const mMap = new Map(); | ||
System = { | ||
register(id, deps, f) { | ||
mMap.set(id, { | ||
id, | ||
deps, | ||
f, | ||
exp: {} | ||
}); | ||
} | ||
}; | ||
|
||
const gC = (data, main) => { | ||
const { id } = data; | ||
return { | ||
id, | ||
import: async id => mMap.get(id)?.exp, | ||
meta: { url: id, main } | ||
}; | ||
}; | ||
|
||
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)) { | ||
Object.defineProperty(exp, id, { | ||
value, | ||
writable: true, | ||
enumerable: true | ||
}); | ||
} | ||
}; | ||
}; | ||
|
||
const iQ = []; | ||
|
||
const enq = ids => { | ||
for (const id of ids) { | ||
if (!iQ.includes(id)) { | ||
const { deps } = mMap.get(id); | ||
iQ.push(id); | ||
enq(deps); | ||
} | ||
} | ||
}; | ||
|
||
const dr = async 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; | ||
} | ||
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 e = execute(); | ||
if (e) await e; | ||
} | ||
}; | ||
|
||
__inst = async id => { | ||
System = undefined; | ||
__inst = undefined; | ||
enq([id]); | ||
await dr(id); | ||
return mMap.get(id)?.exp; | ||
}; | ||
})(); |