mirror of
https://github.com/denoland/deno.git
synced 2025-09-24 11:22:33 +00:00
Improvements to bundling. (#3965)
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 re-exported. Fixes #2553 Fixes #3559 Fixes #3751 Fixes #3825 Refs #3301
This commit is contained in:
parent
3563ab4c53
commit
6bd846a780
10 changed files with 161 additions and 25 deletions
|
@ -1,6 +1,6 @@
|
|||
// Copyright 2018-2020 the Deno authors. All rights reserved. MIT license.
|
||||
|
||||
import { BUNDLE_LOADER } from "./compiler_bootstrap.ts";
|
||||
import { SYSTEM_LOADER } from "./compiler_bootstrap.ts";
|
||||
import {
|
||||
assert,
|
||||
commonPath,
|
||||
|
@ -44,18 +44,18 @@ export function buildBundle(
|
|||
.replace(/\.\w+$/i, "");
|
||||
let instantiate: string;
|
||||
if (rootExports && rootExports.length) {
|
||||
instantiate = `const __rootExports = instantiate("${rootName}");\n`;
|
||||
instantiate = `const __exp = await __inst("${rootName}");\n`;
|
||||
for (const rootExport of rootExports) {
|
||||
if (rootExport === "default") {
|
||||
instantiate += `export default __rootExports["${rootExport}"];\n`;
|
||||
instantiate += `export default __exp["${rootExport}"];\n`;
|
||||
} else {
|
||||
instantiate += `export const ${rootExport} = __rootExports["${rootExport}"];\n`;
|
||||
instantiate += `export const ${rootExport} = __exp["${rootExport}"];\n`;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
instantiate = `instantiate("${rootName}");\n`;
|
||||
instantiate = `await __inst("${rootName}");\n`;
|
||||
}
|
||||
return `${BUNDLE_LOADER}\n${data}\n${instantiate}`;
|
||||
return `${SYSTEM_LOADER}\n${data}\n${instantiate}`;
|
||||
}
|
||||
|
||||
/** Set the rootExports which will by the `emitBundle()` */
|
||||
|
@ -80,6 +80,7 @@ export function setRootExports(program: ts.Program, rootModule: string): void {
|
|||
// out, so inspecting SymbolFlags that might be present that are type only
|
||||
.filter(
|
||||
sym =>
|
||||
sym.flags & ts.SymbolFlags.Class ||
|
||||
!(
|
||||
sym.flags & ts.SymbolFlags.Interface ||
|
||||
sym.flags & ts.SymbolFlags.TypeLiteral ||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue