diff options
author | Bartek IwaĆczuk <biwanczuk@gmail.com> | 2020-01-22 20:18:01 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-01-22 20:18:01 +0100 |
commit | bd9561f4de8f940ce6ed8b5eedfa84161a749c54 (patch) | |
tree | 20bc23c294aa3031fe4729dc09e03351ec6097f4 /cli/js/compiler_bootstrap.ts | |
parent | 3c47718959fb38d51e34c64d423151b5326bae3a (diff) |
Reland "Create an old program to be used in snapshot." (#3747)
* read CLI assets from disk during snapshotting
Diffstat (limited to 'cli/js/compiler_bootstrap.ts')
-rw-r--r-- | cli/js/compiler_bootstrap.ts | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/cli/js/compiler_bootstrap.ts b/cli/js/compiler_bootstrap.ts new file mode 100644 index 000000000..6de978750 --- /dev/null +++ b/cli/js/compiler_bootstrap.ts @@ -0,0 +1,34 @@ +// Copyright 2018-2020 the Deno authors. All rights reserved. MIT license. + +import { ASSETS, Host } from "./compiler_host.ts"; +import { core } from "./core.ts"; +import * as dispatch from "./dispatch.ts"; +import { sendSync } from "./dispatch_json.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; +} + +const host = new Host({ writeFile(): void {} }); +const options = host.getCompilationSettings(); + +/** 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({ + 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 bundleLoader = sendSync(dispatch.OP_FETCH_ASSET, { + name: "bundle_loader.js" +}); |