diff options
Diffstat (limited to 'cli/js/compiler_host.ts')
-rw-r--r-- | cli/js/compiler_host.ts | 21 |
1 files changed, 14 insertions, 7 deletions
diff --git a/cli/js/compiler_host.ts b/cli/js/compiler_host.ts index 0f6aa4d08..8f19eb326 100644 --- a/cli/js/compiler_host.ts +++ b/cli/js/compiler_host.ts @@ -1,6 +1,6 @@ // Copyright 2018-2020 the Deno authors. All rights reserved. MIT license. -import { MediaType, SourceFile } from "./compiler_sourcefile.ts"; +import { ASSETS, MediaType, SourceFile } from "./compiler_sourcefile.ts"; import { OUT_DIR, WriteFileCallback, getAsset } from "./compiler_util.ts"; import { cwd } from "./dir.ts"; import { assert, notImplemented } from "./util.ts"; @@ -18,8 +18,14 @@ export enum CompilerHostTarget { } export interface CompilerHostOptions { + /** Flag determines if the host should assume a single bundle output. */ bundle?: boolean; + + /** Determines what the default library that should be used when type checking + * TS code. */ target: CompilerHostTarget; + + /** A function to be used when the program emit occurs to write out files. */ writeFile: WriteFileCallback; } @@ -28,8 +34,6 @@ export interface ConfigureResponse { diagnostics?: ts.Diagnostic[]; } -export const ASSETS = "$asset$"; - /** Options that need to be used when generating a bundle (either trusted or * runtime). */ export const defaultBundlerOptions: ts.CompilerOptions = { @@ -96,7 +100,6 @@ const ignoredCompilerOptions: readonly string[] = [ "inlineSources", "init", "isolatedModules", - "lib", "listEmittedFiles", "listFiles", "mapRoot", @@ -141,7 +144,10 @@ export class Host implements ts.CompilerHost { private _writeFile: WriteFileCallback; private _getAsset(filename: string): SourceFile { - const url = filename.split("/").pop()!; + const lastSegment = filename.split("/").pop()!; + const url = ts.libMap.has(lastSegment) + ? ts.libMap.get(lastSegment)! + : lastSegment; const sourceFile = SourceFile.get(url); if (sourceFile) { return sourceFile; @@ -150,7 +156,7 @@ export class Host implements ts.CompilerHost { const sourceCode = getAsset(name); return new SourceFile({ url, - filename, + filename: `${ASSETS}/${name}`, mediaType: MediaType.TypeScript, sourceCode }); @@ -230,6 +236,7 @@ export class Host implements ts.CompilerHost { } getDefaultLibFileName(_options: ts.CompilerOptions): string { + util.log("compiler::host.getDefaultLibFileName()"); switch (this._target) { case CompilerHostTarget.Main: case CompilerHostTarget.Runtime: @@ -259,7 +266,7 @@ export class Host implements ts.CompilerHost { if (!sourceFile.tsSourceFile) { assert(sourceFile.sourceCode != null); sourceFile.tsSourceFile = ts.createSourceFile( - fileName, + fileName.startsWith(ASSETS) ? sourceFile.filename : fileName, sourceFile.sourceCode, languageVersion ); |