From fa61956f03491101b6ef64423ea2f1f73af26a73 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bartek=20Iwa=C5=84czuk?= Date: Sun, 19 Jul 2020 19:49:44 +0200 Subject: Port internal TS code to JS (#6793) Co-authored-by: Ryan Dahl --- cli/js/compiler_api.ts | 86 -------------------------------------------------- 1 file changed, 86 deletions(-) delete mode 100644 cli/js/compiler_api.ts (limited to 'cli/js/compiler_api.ts') diff --git a/cli/js/compiler_api.ts b/cli/js/compiler_api.ts deleted file mode 100644 index e0488b7f6..000000000 --- a/cli/js/compiler_api.ts +++ /dev/null @@ -1,86 +0,0 @@ -// Copyright 2018-2020 the Deno authors. All rights reserved. MIT license. - -// This file contains the runtime APIs which will dispatch work to the internal -// compiler within Deno. - -import type { DiagnosticItem } from "./diagnostics.ts"; -import * as util from "./util.ts"; -import * as runtimeCompilerOps from "./ops/runtime_compiler.ts"; -import type { TranspileOnlyResult } from "./ops/runtime_compiler.ts"; -import type { CompilerOptions } from "./compiler_options.ts"; - -function checkRelative(specifier: string): string { - return specifier.match(/^([\.\/\\]|https?:\/{2}|file:\/{2})/) - ? specifier - : `./${specifier}`; -} - -// TODO(bartlomieju): change return type to interface? -export function transpileOnly( - sources: Record, - options: CompilerOptions = {}, -): Promise> { - util.log("Deno.transpileOnly", { sources: Object.keys(sources), options }); - const payload = { - sources, - options: JSON.stringify(options), - }; - return runtimeCompilerOps.transpile(payload); -} - -// TODO(bartlomieju): change return type to interface? -export async function compile( - rootName: string, - sources?: Record, - options: CompilerOptions = {}, -): Promise<[DiagnosticItem[] | undefined, Record]> { - const payload = { - rootName: sources ? rootName : checkRelative(rootName), - sources, - options: JSON.stringify(options), - bundle: false, - }; - util.log("Deno.compile", { - rootName: payload.rootName, - sources: !!sources, - options, - }); - const result = await runtimeCompilerOps.compile(payload); - util.assert(result.emitMap); - const maybeDiagnostics = result.diagnostics.length === 0 - ? undefined - : result.diagnostics; - - const emitMap: Record = {}; - - for (const [key, emittedSource] of Object.entries(result.emitMap)) { - emitMap[key] = emittedSource.contents; - } - - return [maybeDiagnostics, emitMap]; -} - -// TODO(bartlomieju): change return type to interface? -export async function bundle( - rootName: string, - sources?: Record, - options: CompilerOptions = {}, -): Promise<[DiagnosticItem[] | undefined, string]> { - const payload = { - rootName: sources ? rootName : checkRelative(rootName), - sources, - options: JSON.stringify(options), - bundle: true, - }; - util.log("Deno.bundle", { - rootName: payload.rootName, - sources: !!sources, - options, - }); - const result = await runtimeCompilerOps.compile(payload); - util.assert(result.output); - const maybeDiagnostics = result.diagnostics.length === 0 - ? undefined - : result.diagnostics; - return [maybeDiagnostics, result.output]; -} -- cgit v1.2.3