summaryrefslogtreecommitdiff
path: root/cli/js/compiler/api.ts
diff options
context:
space:
mode:
authorBartek IwaƄczuk <biwanczuk@gmail.com>2020-05-05 18:23:15 +0200
committerGitHub <noreply@github.com>2020-05-05 18:23:15 +0200
commitcf5a39a36127e8df70ac34b9895771fb41d474a6 (patch)
treeeb980f37b328902445ed5141b9c3c8a999ef84f7 /cli/js/compiler/api.ts
parente574437922db0693e7be7a5df7c474f306e55f7b (diff)
refactor(ts): remove op_cache (#5071)
This PR removes op_cache and refactors how Deno interacts with TS compiler. Ultimate goal is to completely sandbox TS compiler worker; it should operate on simple request -> response basis. With this commit TS compiler no longer caches compiled sources as they are generated but rather collects all sources and sends them back to Rust when compilation is done. Additionally "Diagnostic" and its children got refactored to use "Deserialize" trait instead of manually implementing JSON deserialization.
Diffstat (limited to 'cli/js/compiler/api.ts')
-rw-r--r--cli/js/compiler/api.ts32
1 files changed, 22 insertions, 10 deletions
diff --git a/cli/js/compiler/api.ts b/cli/js/compiler/api.ts
index b7c57b528..a7d1e57a8 100644
--- a/cli/js/compiler/api.ts
+++ b/cli/js/compiler/api.ts
@@ -6,6 +6,8 @@
import { DiagnosticItem } from "../diagnostics.ts";
import * as util from "../util.ts";
import * as runtimeCompilerOps from "../ops/runtime_compiler.ts";
+import { TranspileOnlyResult } from "../ops/runtime_compiler.ts";
+export { TranspileOnlyResult } from "../ops/runtime_compiler.ts";
export interface CompilerOptions {
allowJs?: boolean;
@@ -145,12 +147,8 @@ function checkRelative(specifier: string): string {
: `./${specifier}`;
}
-export interface TranspileOnlyResult {
- source: string;
- map?: string;
-}
-
-export async function transpileOnly(
+// TODO(bartlomieju): change return type to interface?
+export function transpileOnly(
sources: Record<string, string>,
options: CompilerOptions = {}
): Promise<Record<string, TranspileOnlyResult>> {
@@ -159,10 +157,10 @@ export async function transpileOnly(
sources,
options: JSON.stringify(options),
};
- const result = await runtimeCompilerOps.transpile(payload);
- return JSON.parse(result);
+ return runtimeCompilerOps.transpile(payload);
}
+// TODO(bartlomieju): change return type to interface?
export async function compile(
rootName: string,
sources?: Record<string, string>,
@@ -180,9 +178,20 @@ export async function compile(
options,
});
const result = await runtimeCompilerOps.compile(payload);
- return JSON.parse(result);
+ util.assert(result.emitMap);
+ const maybeDiagnostics =
+ result.diagnostics.length === 0 ? undefined : result.diagnostics;
+
+ const emitMap: Record<string, string> = {};
+
+ for (const [key, emmitedSource] of Object.entries(result.emitMap)) {
+ emitMap[key] = emmitedSource.contents;
+ }
+
+ return [maybeDiagnostics, emitMap];
}
+// TODO(bartlomieju): change return type to interface?
export async function bundle(
rootName: string,
sources?: Record<string, string>,
@@ -200,5 +209,8 @@ export async function bundle(
options,
});
const result = await runtimeCompilerOps.compile(payload);
- return JSON.parse(result);
+ util.assert(result.output);
+ const maybeDiagnostics =
+ result.diagnostics.length === 0 ? undefined : result.diagnostics;
+ return [maybeDiagnostics, result.output];
}