diff options
author | Bartek IwaĆczuk <biwanczuk@gmail.com> | 2019-08-24 15:02:42 +0200 |
---|---|---|
committer | Ryan Dahl <ry@tinyclouds.org> | 2019-08-24 06:02:42 -0700 |
commit | 79f82cf10ed1dbf91346994250d7311a4d74377a (patch) | |
tree | b00755d666198b9c66264a3c240f849096951e2f /js/compiler.ts | |
parent | 5b2baa5c990fbeae747e952c5dcd7a5369e950b1 (diff) |
port ops to JSON: compiler, errors, fetch, files (#2804)
Diffstat (limited to 'js/compiler.ts')
-rw-r--r-- | js/compiler.ts | 56 |
1 files changed, 13 insertions, 43 deletions
diff --git a/js/compiler.ts b/js/compiler.ts index 7519c5115..5399d59ad 100644 --- a/js/compiler.ts +++ b/js/compiler.ts @@ -7,9 +7,11 @@ import { Console } from "./console"; import { core } from "./core"; import { Diagnostic, fromTypeScriptDiagnostic } from "./diagnostics"; import { cwd } from "./dir"; -import { sendSync, msg, flatbuffers } from "./dispatch_flatbuffers"; +import * as dispatch from "./dispatch"; +import { sendSync } from "./dispatch_json"; +import { msg } from "./dispatch_flatbuffers"; import * as os from "./os"; -import { TextDecoder, TextEncoder } from "./text_encoding"; +import { TextEncoder } from "./text_encoding"; import { getMappedModuleName, parseTypeDirectives } from "./type_directives"; import { assert, notImplemented } from "./util"; import * as util from "./util"; @@ -121,35 +123,15 @@ interface EmitResult { /** Ops to Rust to resolve and fetch a modules meta data. */ function fetchSourceFile(specifier: string, referrer: string): SourceFile { - util.log("fetchSourceFile", { specifier, referrer }); - // Send FetchSourceFile message - const builder = flatbuffers.createBuilder(); - const specifier_ = builder.createString(specifier); - const referrer_ = builder.createString(referrer); - const inner = msg.FetchSourceFile.createFetchSourceFile( - builder, - specifier_, - referrer_ - ); - const baseRes = sendSync(builder, msg.Any.FetchSourceFile, inner); - assert(baseRes != null); - assert( - msg.Any.FetchSourceFileRes === baseRes!.innerType(), - `base.innerType() unexpectedly is ${baseRes!.innerType()}` - ); - const fetchSourceFileRes = new msg.FetchSourceFileRes(); - assert(baseRes!.inner(fetchSourceFileRes) != null); - const dataArray = fetchSourceFileRes.dataArray(); - const decoder = new TextDecoder(); - const sourceCode = dataArray ? decoder.decode(dataArray) : undefined; - // flatbuffers returns `null` for an empty value, this does not fit well with - // idiomatic TypeScript under strict null checks, so converting to `undefined` + util.log("compiler.fetchSourceFile", { specifier, referrer }); + const res = sendSync(dispatch.OP_FETCH_SOURCE_FILE, { + specifier, + referrer + }); + return { - moduleName: fetchSourceFileRes.moduleName() || undefined, - filename: fetchSourceFileRes.filename() || undefined, - mediaType: fetchSourceFileRes.mediaType(), - sourceCode, - typeDirectives: parseTypeDirectives(sourceCode) + ...res, + typeDirectives: parseTypeDirectives(res.sourceCode) }; } @@ -171,19 +153,7 @@ function humanFileSize(bytes: number): string { /** Ops to rest for caching source map and compiled js */ function cache(extension: string, moduleId: string, contents: string): void { - util.log("cache", extension, moduleId); - const builder = flatbuffers.createBuilder(); - const extension_ = builder.createString(extension); - const moduleId_ = builder.createString(moduleId); - const contents_ = builder.createString(contents); - const inner = msg.Cache.createCache( - builder, - extension_, - moduleId_, - contents_ - ); - const baseRes = sendSync(builder, msg.Any.Cache, inner); - assert(baseRes == null); + sendSync(dispatch.OP_CACHE, { extension, moduleId, contents }); } const encoder = new TextEncoder(); |