diff options
author | Kitson Kelly <me@kitsonkelly.com> | 2020-02-19 16:34:11 +1100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-02-19 00:34:11 -0500 |
commit | 046bbb26913f9da58b0d23ae331e9dab9dc19e59 (patch) | |
tree | 74dd5945ed1ff10ce84fea05c73d9c13b31ad376 /cli/js/compiler_util.ts | |
parent | 3d5bed35e032ee20e4fe34cad925202c6f0c0d3e (diff) |
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.
Diffstat (limited to 'cli/js/compiler_util.ts')
-rw-r--r-- | cli/js/compiler_util.ts | 22 |
1 files changed, 13 insertions, 9 deletions
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!); } |