diff options
author | Ryan Dahl <ry@tinyclouds.org> | 2019-08-24 13:20:48 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-08-24 13:20:48 -0700 |
commit | 2235dd795d3cc6c24ff1bdd1bbdcd110b4b0bdfc (patch) | |
tree | a5811adc062cbb1c66f05c863c9be245cf4fd2d2 /js/compiler.ts | |
parent | bdc0a13261deaa3748f51d9948b4e7b92864c324 (diff) |
Revert json ops (#2814)
* Revert "port more ops to JSON (#2809)"
This reverts commit 137f33733d365026903d40e7cde6e34ac6c36dcf.
* Revert "port ops to JSON: compiler, errors, fetch, files (#2804)"
This reverts commit 79f82cf10ed1dbf91346994250d7311a4d74377a.
* Revert "Port rest of os ops to JSON (#2802)"
This reverts commit 5b2baa5c990fbeae747e952c5dcd7a5369e950b1.
Diffstat (limited to 'js/compiler.ts')
-rw-r--r-- | js/compiler.ts | 56 |
1 files changed, 43 insertions, 13 deletions
diff --git a/js/compiler.ts b/js/compiler.ts index 5399d59ad..7519c5115 100644 --- a/js/compiler.ts +++ b/js/compiler.ts @@ -7,11 +7,9 @@ import { Console } from "./console"; import { core } from "./core"; import { Diagnostic, fromTypeScriptDiagnostic } from "./diagnostics"; import { cwd } from "./dir"; -import * as dispatch from "./dispatch"; -import { sendSync } from "./dispatch_json"; -import { msg } from "./dispatch_flatbuffers"; +import { sendSync, msg, flatbuffers } from "./dispatch_flatbuffers"; import * as os from "./os"; -import { TextEncoder } from "./text_encoding"; +import { TextDecoder, TextEncoder } from "./text_encoding"; import { getMappedModuleName, parseTypeDirectives } from "./type_directives"; import { assert, notImplemented } from "./util"; import * as util from "./util"; @@ -123,15 +121,35 @@ interface EmitResult { /** Ops to Rust to resolve and fetch a modules meta data. */ function fetchSourceFile(specifier: string, referrer: string): SourceFile { - util.log("compiler.fetchSourceFile", { specifier, referrer }); - const res = sendSync(dispatch.OP_FETCH_SOURCE_FILE, { - specifier, - referrer - }); - + 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` return { - ...res, - typeDirectives: parseTypeDirectives(res.sourceCode) + moduleName: fetchSourceFileRes.moduleName() || undefined, + filename: fetchSourceFileRes.filename() || undefined, + mediaType: fetchSourceFileRes.mediaType(), + sourceCode, + typeDirectives: parseTypeDirectives(sourceCode) }; } @@ -153,7 +171,19 @@ function humanFileSize(bytes: number): string { /** Ops to rest for caching source map and compiled js */ function cache(extension: string, moduleId: string, contents: string): void { - sendSync(dispatch.OP_CACHE, { extension, moduleId, contents }); + 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); } const encoder = new TextEncoder(); |