diff options
author | Kitson Kelly <me@kitsonkelly.com> | 2018-08-23 21:07:01 -0700 |
---|---|---|
committer | Ryan Dahl <ry@tinyclouds.org> | 2018-08-24 17:16:54 -0400 |
commit | c003df53ab1aba724cdd6a7566302f72d0df97d7 (patch) | |
tree | 0ba7f910c27a8284c38364cabca534875719e1c4 /js/compiler.ts | |
parent | a4b3741b4de389c1a2dc4543f6ee1a031699f8ea (diff) |
Integrate ScriptSnapshot into ModuleMetaData
Diffstat (limited to 'js/compiler.ts')
-rw-r--r-- | js/compiler.ts | 36 |
1 files changed, 15 insertions, 21 deletions
diff --git a/js/compiler.ts b/js/compiler.ts index fcbfc7c5e..93cfd34c1 100644 --- a/js/compiler.ts +++ b/js/compiler.ts @@ -57,9 +57,8 @@ export interface Ts { * Named `ModuleMetaData` to clarify it is just a representation of meta data of * the module, not the actual module instance. */ -export class ModuleMetaData { +export class ModuleMetaData implements ts.IScriptSnapshot { public readonly exports = {}; - public scriptSnapshot?: ts.IScriptSnapshot; public scriptVersion = ""; constructor( @@ -71,6 +70,19 @@ export class ModuleMetaData { this.scriptVersion = "1"; } } + + public getText(start: number, end: number): string { + return this.sourceCode.substring(start, end); + } + + public getLength(): number { + return this.sourceCode.length; + } + + public getChangeRange(): undefined { + // Required `IScriptSnapshot` API, but not implemented/needed in deno + return undefined; + } } /** @@ -478,25 +490,7 @@ export class DenoCompiler implements ts.LanguageServiceHost { getScriptSnapshot(fileName: ModuleFileName): ts.IScriptSnapshot | undefined { this._log("getScriptSnapshot()", fileName); - const moduleMetaData = this._getModuleMetaData(fileName); - if (moduleMetaData) { - return ( - moduleMetaData.scriptSnapshot || - (moduleMetaData.scriptSnapshot = { - getText(start, end) { - return moduleMetaData.sourceCode.substring(start, end); - }, - getLength() { - return moduleMetaData.sourceCode.length; - }, - getChangeRange() { - return undefined; - } - }) - ); - } else { - return undefined; - } + return this._getModuleMetaData(fileName); } getCurrentDirectory(): string { |