From 046bbb26913f9da58b0d23ae331e9dab9dc19e59 Mon Sep 17 00:00:00 2001 From: Kitson Kelly Date: Wed, 19 Feb 2020 16:34:11 +1100 Subject: Support loading additional TS lib files (#3863) Fixes #3726 This PR provides support for referencing other lib files (like lib.dom.d.ts that are not used by default in Deno. --- cli/js/compiler_util.ts | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) (limited to 'cli/js/compiler_util.ts') diff --git a/cli/js/compiler_util.ts b/cli/js/compiler_util.ts index b58d8da43..a28e2d109 100644 --- a/cli/js/compiler_util.ts +++ b/cli/js/compiler_util.ts @@ -92,15 +92,19 @@ function cache( } let OP_FETCH_ASSET: number; +const encoder = new TextEncoder(); +const decoder = new TextDecoder(); -/** - * 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. - */ +/** Retrieve an asset from Rust. */ export function getAsset(name: string): string { + // this path should only be called for assets that are lazily loaded at + // runtime + if (dispatch.OP_FETCH_ASSET) { + util.log("compiler_util::getAsset", name); + return sendSync(dispatch.OP_FETCH_ASSET, { name }).sourceCode; + } + + // this path should only be taken during snapshotting if (!OP_FETCH_ASSET) { const ops = core.ops(); const opFetchAsset = ops["fetch_asset"]; @@ -108,8 +112,8 @@ export function getAsset(name: string): string { OP_FETCH_ASSET = opFetchAsset; } - const encoder = new TextEncoder(); - const decoder = new TextDecoder(); + // We really don't want to depend on JSON dispatch during snapshotting, so + // this op exchanges strings with Rust as raw byte arrays. const sourceCodeBytes = core.dispatch(OP_FETCH_ASSET, encoder.encode(name)); return decoder.decode(sourceCodeBytes!); } -- cgit v1.2.3