diff options
author | Bartek IwaĆczuk <biwanczuk@gmail.com> | 2020-01-28 03:12:25 +0100 |
---|---|---|
committer | Ryan Dahl <ry@tinyclouds.org> | 2020-01-27 21:12:25 -0500 |
commit | ac10d79d231d3b66b918764b9706597321850687 (patch) | |
tree | 6a781c58075ee0c68091e71d2ffd2bb898dc9dfd /cli/js/compiler_bootstrap.ts | |
parent | f604becaba0c747fdf8dd9d0d744c7bd19322e41 (diff) |
refactor: isomorphic snapshot for CLI (#3728)
Diffstat (limited to 'cli/js/compiler_bootstrap.ts')
-rw-r--r-- | cli/js/compiler_bootstrap.ts | 31 |
1 files changed, 13 insertions, 18 deletions
diff --git a/cli/js/compiler_bootstrap.ts b/cli/js/compiler_bootstrap.ts index a5c7eb029..afb3d2be5 100644 --- a/cli/js/compiler_bootstrap.ts +++ b/cli/js/compiler_bootstrap.ts @@ -1,20 +1,11 @@ // Copyright 2018-2020 the Deno authors. All rights reserved. MIT license. 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"; -// This registers ops that are available during the snapshotting process. -const ops = core.ops(); -for (const [name, opId] of Object.entries(ops)) { - const opName = `OP_${name.toUpperCase()}`; - // TODO This type casting is dangerous, and should be improved when the same - // code in `os.ts` is done. - // eslint-disable-next-line @typescript-eslint/no-explicit-any - (dispatch as any)[opName] = opId; -} - +// 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 {} @@ -35,11 +26,15 @@ const options = host.getCompilationSettings(); 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({ +/** + * 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 @@ -49,5 +44,5 @@ export const oldProgram = ts.createProgram({ * * We read all static assets during the snapshotting process, which is * why this is located in compiler_bootstrap. - **/ -export const bundleLoader = getAsset("bundle_loader.js"); + */ +export const BUNDLE_LOADER = getAsset("bundle_loader.js"); |