summaryrefslogtreecommitdiff
path: root/js/os.ts
diff options
context:
space:
mode:
authorKitson Kelly <me@kitsonkelly.com>2018-10-22 13:14:27 +1100
committerRyan Dahl <ry@tinyclouds.org>2018-10-23 04:48:00 -0700
commit8ef7da261149ed03f25bdb5ea2611f8ce84a4d78 (patch)
tree8399dd030cf6fb172980d3b2c65bcf82d62b1168 /js/os.ts
parentc0492ef061afd5af2044d5952432d223615841a7 (diff)
Enforce media types
Diffstat (limited to 'js/os.ts')
-rw-r--r--js/os.ts22
1 files changed, 16 insertions, 6 deletions
diff --git a/js/os.ts b/js/os.ts
index a4a7d3cc7..0d54de998 100644
--- a/js/os.ts
+++ b/js/os.ts
@@ -1,11 +1,18 @@
// Copyright 2018 the Deno authors. All rights reserved. MIT license.
-import { ModuleInfo } from "./types";
import * as msg from "gen/msg_generated";
import { assert } from "./util";
import * as util from "./util";
import * as flatbuffers from "./flatbuffers";
import { sendSync } from "./dispatch";
+interface CodeInfo {
+ moduleName: string | undefined;
+ filename: string | undefined;
+ mediaType: msg.MediaType;
+ sourceCode: string | undefined;
+ outputCode: string | undefined;
+}
+
/** Exit the Deno process with optional exit code. */
export function exit(exitCode = 0): never {
const builder = flatbuffers.createBuilder();
@@ -20,7 +27,7 @@ export function exit(exitCode = 0): never {
export function codeFetch(
moduleSpecifier: string,
containingFile: string
-): ModuleInfo {
+): CodeInfo {
util.log("os.ts codeFetch", moduleSpecifier, containingFile);
// Send CodeFetch message
const builder = flatbuffers.createBuilder();
@@ -38,11 +45,14 @@ export function codeFetch(
);
const codeFetchRes = new msg.CodeFetchRes();
assert(baseRes!.inner(codeFetchRes) != null);
+ // flatbuffers returns `null` for an empty value, this does not fit well with
+ // idiomatic TypeScript under strict null checks, so converting to `undefined`
return {
- moduleName: codeFetchRes.moduleName(),
- filename: codeFetchRes.filename(),
- sourceCode: codeFetchRes.sourceCode(),
- outputCode: codeFetchRes.outputCode()
+ moduleName: codeFetchRes.moduleName() || undefined,
+ filename: codeFetchRes.filename() || undefined,
+ mediaType: codeFetchRes.mediaType(),
+ sourceCode: codeFetchRes.sourceCode() || undefined,
+ outputCode: codeFetchRes.outputCode() || undefined
};
}