diff options
author | Kitson Kelly <me@kitsonkelly.com> | 2018-10-22 13:14:27 +1100 |
---|---|---|
committer | Ryan Dahl <ry@tinyclouds.org> | 2018-10-23 04:48:00 -0700 |
commit | 8ef7da261149ed03f25bdb5ea2611f8ce84a4d78 (patch) | |
tree | 8399dd030cf6fb172980d3b2c65bcf82d62b1168 /js/os.ts | |
parent | c0492ef061afd5af2044d5952432d223615841a7 (diff) |
Enforce media types
Diffstat (limited to 'js/os.ts')
-rw-r--r-- | js/os.ts | 22 |
1 files changed, 16 insertions, 6 deletions
@@ -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 }; } |