summaryrefslogtreecommitdiff
path: root/cli/js/compiler_bootstrap.ts
diff options
context:
space:
mode:
authorKitson Kelly <me@kitsonkelly.com>2020-01-25 06:15:01 +1100
committerRyan Dahl <ry@tinyclouds.org>2020-01-24 14:15:01 -0500
commit950537e8ef6e54c409a7fcafa0b087e68988d9ef (patch)
tree46162f11adc5a6e71c4c681ffe7949ad7bc98fb8 /cli/js/compiler_bootstrap.ts
parent8bc639a23e141d350e35ea112a4a9be2ea536fe6 (diff)
Break out runtime lib to main and worker (#3771)
Co-authored-by: Bartek IwaƄczuk <biwanczuk@gmail.com>
Diffstat (limited to 'cli/js/compiler_bootstrap.ts')
-rw-r--r--cli/js/compiler_bootstrap.ts23
1 files changed, 21 insertions, 2 deletions
diff --git a/cli/js/compiler_bootstrap.ts b/cli/js/compiler_bootstrap.ts
index 31e5774bf..a5c7eb029 100644
--- a/cli/js/compiler_bootstrap.ts
+++ b/cli/js/compiler_bootstrap.ts
@@ -1,6 +1,6 @@
// Copyright 2018-2020 the Deno authors. All rights reserved. MIT license.
-import { ASSETS, Host } from "./compiler_host.ts";
+import { ASSETS, CompilerHostTarget, Host } from "./compiler_host.ts";
import { core } from "./core.ts";
import * as dispatch from "./dispatch.ts";
import { getAsset } from "./compiler_util.ts";
@@ -15,9 +15,28 @@ for (const [name, opId] of Object.entries(ops)) {
(dispatch as any)[opName] = opId;
}
-const host = new Host({ writeFile(): void {} });
+const host = new Host({
+ target: CompilerHostTarget.Main,
+ writeFile(): void {}
+});
const options = host.getCompilationSettings();
+// This is a hacky way of adding our libs to the libs available in TypeScript()
+// as these are internal APIs of TypeScript which maintain valid libs
+/* eslint-disable @typescript-eslint/no-explicit-any */
+(ts as any).libs.push("deno_main", "deno_worker", "deno");
+(ts as any).libMap.set("deno_main", "lib.deno_main.d.ts");
+(ts as any).libMap.set("deno_worker", "lib.deno_worker.d.ts");
+(ts as any).libMap.set("deno", "lib.deno.d.ts");
+/* eslint-enable @typescript-eslint/no-explicit-any */
+
+// this pre-populates the cache at snapshot time of our library files, so they
+// are available in the future when needed.
+host.getSourceFile(`${ASSETS}/lib.deno_main.d.ts`, ts.ScriptTarget.ESNext);
+host.getSourceFile(`${ASSETS}/lib.deno_worker.d.ts`, ts.ScriptTarget.ESNext);
+host.getSourceFile(`${ASSETS}/lib.deno.d.ts`, ts.ScriptTarget.ESNext);
+host.getSourceFile(`${ASSETS}/lib.webworker.d.ts`, ts.ScriptTarget.ESNext);
+
/** Used to generate the foundational AST for all other compilations, so it can
* be cached as part of the snapshot and available to speed up startup */
export const oldProgram = ts.createProgram({