diff options
author | Bartek IwaĆczuk <biwanczuk@gmail.com> | 2020-03-11 10:53:06 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-03-11 10:53:06 +0100 |
commit | 99a0c6df79b903e4fe72ce066787039bdede3868 (patch) | |
tree | 1c0abdb964a2e052b593dc8fa3e515f76dbc0642 /cli/js/compiler/bootstrap.ts | |
parent | 94f4c6807a34a564f567b984e71e36e9cb9c5005 (diff) |
reorg: cli/js/compiler/, move more API to cli/js/web/ (#4310)
- moves compiler implementation to "cli/js/compiler/" directory
- moves more APIs to "cli/js/web":
* "console.ts"
* "console_table.ts"
* "performance.ts"
* "timers.ts"
* "workers.ts"
- removes some dead code from "cli/js/"
Diffstat (limited to 'cli/js/compiler/bootstrap.ts')
-rw-r--r-- | cli/js/compiler/bootstrap.ts | 52 |
1 files changed, 52 insertions, 0 deletions
diff --git a/cli/js/compiler/bootstrap.ts b/cli/js/compiler/bootstrap.ts new file mode 100644 index 000000000..d4642d041 --- /dev/null +++ b/cli/js/compiler/bootstrap.ts @@ -0,0 +1,52 @@ +// Copyright 2018-2020 the Deno authors. All rights reserved. MIT license. + +import { CompilerHostTarget, Host } from "./host.ts"; +import { ASSETS } from "./sourcefile.ts"; +import { getAsset } from "./util.ts"; + +// NOTE: target doesn't really matter here, +// this is in fact a mock host created just to +// load all type definitions and snapshot them. +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 +ts.libs.push("deno.ns", "deno.window", "deno.worker", "deno.shared_globals"); +ts.libMap.set("deno.ns", "lib.deno.ns.d.ts"); +ts.libMap.set("deno.window", "lib.deno.window.d.ts"); +ts.libMap.set("deno.worker", "lib.deno.worker.d.ts"); +ts.libMap.set("deno.shared_globals", "lib.deno.shared_globals.d.ts"); + +// 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.ns.d.ts`, ts.ScriptTarget.ESNext); +host.getSourceFile(`${ASSETS}/lib.deno.window.d.ts`, ts.ScriptTarget.ESNext); +host.getSourceFile(`${ASSETS}/lib.deno.worker.d.ts`, ts.ScriptTarget.ESNext); +host.getSourceFile( + `${ASSETS}/lib.deno.shared_globals.d.ts`, + ts.ScriptTarget.ESNext +); + +/** + * This function spins up TS compiler and loads all available libraries + * into memory (including ones specified above). + * + * 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 TS_SNAPSHOT_PROGRAM = ts.createProgram({ + rootNames: [`${ASSETS}/bootstrap.ts`], + options, + host +}); + +/** A module loader which is concatenated into bundle files. + * + * We read all static assets during the snapshotting process, which is + * why this is located in compiler_bootstrap. + */ +export const SYSTEM_LOADER = getAsset("system_loader.js"); |