diff options
Diffstat (limited to 'cli/js')
-rw-r--r-- | cli/js/compiler_bootstrap.ts | 14 | ||||
-rw-r--r-- | cli/js/compiler_host.ts | 6 | ||||
-rw-r--r-- | cli/js/compiler_util.ts | 22 |
3 files changed, 28 insertions, 14 deletions
diff --git a/cli/js/compiler_bootstrap.ts b/cli/js/compiler_bootstrap.ts index 6de978750..31e5774bf 100644 --- a/cli/js/compiler_bootstrap.ts +++ b/cli/js/compiler_bootstrap.ts @@ -3,7 +3,7 @@ import { ASSETS, Host } from "./compiler_host.ts"; import { core } from "./core.ts"; import * as dispatch from "./dispatch.ts"; -import { sendSync } from "./dispatch_json.ts"; +import { getAsset } from "./compiler_util.ts"; // This registers ops that are available during the snapshotting process. const ops = core.ops(); @@ -26,9 +26,9 @@ export const oldProgram = ts.createProgram({ 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" -}); +/** 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 = getAsset("bundle_loader.js"); diff --git a/cli/js/compiler_host.ts b/cli/js/compiler_host.ts index 3e6df4485..bff16757b 100644 --- a/cli/js/compiler_host.ts +++ b/cli/js/compiler_host.ts @@ -1,10 +1,8 @@ // Copyright 2018-2020 the Deno authors. All rights reserved. MIT license. import { MediaType, SourceFile } from "./compiler_sourcefile.ts"; -import { OUT_DIR, WriteFileCallback } from "./compiler_util.ts"; +import { OUT_DIR, WriteFileCallback, getAsset } from "./compiler_util.ts"; import { cwd } from "./dir.ts"; -import { sendSync } from "./dispatch_json.ts"; -import * as dispatch from "./dispatch.ts"; import { assert, notImplemented } from "./util.ts"; import * as util from "./util.ts"; @@ -135,7 +133,7 @@ export class Host implements ts.CompilerHost { return sourceFile; } const name = url.includes(".") ? url : `${url}.d.ts`; - const sourceCode = sendSync(dispatch.OP_FETCH_ASSET, { name }); + const sourceCode = getAsset(name); return new SourceFile({ url, filename, diff --git a/cli/js/compiler_util.ts b/cli/js/compiler_util.ts index bff3bcd51..fbb30d67d 100644 --- a/cli/js/compiler_util.ts +++ b/cli/js/compiler_util.ts @@ -7,7 +7,8 @@ import { ConfigureResponse, Host } from "./compiler_host.ts"; import { SourceFile } from "./compiler_sourcefile.ts"; import { sendSync } from "./dispatch_json.ts"; import * as dispatch from "./dispatch.ts"; -import { TextEncoder } from "./text_encoding.ts"; +import { TextDecoder, TextEncoder } from "./text_encoding.ts"; +import { core } from "./core.ts"; import * as util from "./util.ts"; import { assert } from "./util.ts"; import { writeFileSync } from "./write_file.ts"; @@ -89,12 +90,27 @@ function cache( assert(false, `Trying to cache unhandled file type "${emittedFileName}"`); } } - -const encoder = new TextEncoder(); +/** + * This op is called only during snapshotting. + * + * We really don't want to depend on JSON dispatch + * during snapshotting, so this op exchanges strings with Rust + * as raw byte arrays. + */ +export function getAsset(name: string): string { + const encoder = new TextEncoder(); + const decoder = new TextDecoder(); + const sourceCodeBytes = core.dispatch( + dispatch.OP_FETCH_ASSET, + encoder.encode(name) + ); + return decoder.decode(sourceCodeBytes!); +} /** Generates a `writeFile` function which can be passed to the compiler `Host` * to use when emitting files. */ export function createWriteFile(state: WriteFileState): WriteFileCallback { + const encoder = new TextEncoder(); if (state.type === CompilerRequestType.Compile) { return function writeFile( fileName: string, |