mirror of
https://github.com/denoland/deno.git
synced 2025-07-24 05:35:33 +00:00
bring back json ops (#2815)
This commit is contained in:
parent
017f88ee99
commit
520f9631e0
45 changed files with 1045 additions and 1968 deletions
|
@ -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();
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue