diff options
author | Kitson Kelly <me@kitsonkelly.com> | 2020-02-19 16:34:11 +1100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-02-19 00:34:11 -0500 |
commit | 046bbb26913f9da58b0d23ae331e9dab9dc19e59 (patch) | |
tree | 74dd5945ed1ff10ce84fea05c73d9c13b31ad376 /cli/js/compiler_host.ts | |
parent | 3d5bed35e032ee20e4fe34cad925202c6f0c0d3e (diff) |
Support loading additional TS lib files (#3863)
Fixes #3726
This PR provides support for referencing other lib files (like lib.dom.d.ts that are not
used by default in Deno.
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 ); |