summaryrefslogtreecommitdiff
path: root/cli/js/compiler_host.ts
diff options
context:
space:
mode:
authorKitson Kelly <me@kitsonkelly.com>2020-01-25 06:15:01 +1100
committerRyan Dahl <ry@tinyclouds.org>2020-01-24 14:15:01 -0500
commit950537e8ef6e54c409a7fcafa0b087e68988d9ef (patch)
tree46162f11adc5a6e71c4c681ffe7949ad7bc98fb8 /cli/js/compiler_host.ts
parent8bc639a23e141d350e35ea112a4a9be2ea536fe6 (diff)
Break out runtime lib to main and worker (#3771)
Co-authored-by: Bartek IwaƄczuk <biwanczuk@gmail.com>
Diffstat (limited to 'cli/js/compiler_host.ts')
-rw-r--r--cli/js/compiler_host.ts25
1 files changed, 23 insertions, 2 deletions
diff --git a/cli/js/compiler_host.ts b/cli/js/compiler_host.ts
index bff16757b..619ce702a 100644
--- a/cli/js/compiler_host.ts
+++ b/cli/js/compiler_host.ts
@@ -6,8 +6,20 @@ import { cwd } from "./dir.ts";
import { assert, notImplemented } from "./util.ts";
import * as util from "./util.ts";
+/** Specifies the target that the host should use to inform the TypeScript
+ * compiler of what types should be used to validate the program against. */
+export enum CompilerHostTarget {
+ /** The main isolate library, where the main program runs. */
+ Main = "main",
+ /** The runtime API library. */
+ Runtime = "runtime",
+ /** The worker isolate library, where worker programs run. */
+ Worker = "worker"
+}
+
export interface CompilerHostOptions {
bundle?: boolean;
+ target: CompilerHostTarget;
writeFile: WriteFileCallback;
}
@@ -124,6 +136,8 @@ const ignoredCompilerOptions: readonly string[] = [
export class Host implements ts.CompilerHost {
private readonly _options = defaultCompileOptions;
+ private _target: CompilerHostTarget;
+
private _writeFile: WriteFileCallback;
private _getAsset(filename: string): SourceFile {
@@ -146,7 +160,8 @@ export class Host implements ts.CompilerHost {
/** Provides the `ts.HostCompiler` interface for Deno. */
constructor(options: CompilerHostOptions) {
- const { bundle = false, writeFile } = options;
+ const { bundle = false, target, writeFile } = options;
+ this._target = target;
this._writeFile = writeFile;
if (bundle) {
// options we need to change when we are generating a bundle
@@ -215,7 +230,13 @@ export class Host implements ts.CompilerHost {
}
getDefaultLibFileName(_options: ts.CompilerOptions): string {
- return ASSETS + "/lib.deno_runtime.d.ts";
+ switch (this._target) {
+ case CompilerHostTarget.Main:
+ case CompilerHostTarget.Runtime:
+ return `${ASSETS}/lib.deno_main.d.ts`;
+ case CompilerHostTarget.Worker:
+ return `${ASSETS}/lib.deno_worker.d.ts`;
+ }
}
getNewLine(): string {