diff options
Diffstat (limited to 'js/compiler.ts')
-rw-r--r-- | js/compiler.ts | 48 |
1 files changed, 7 insertions, 41 deletions
diff --git a/js/compiler.ts b/js/compiler.ts index c9fa4611c..e0bfb77bb 100644 --- a/js/compiler.ts +++ b/js/compiler.ts @@ -3,10 +3,8 @@ import * as ts from "typescript"; import { MediaType } from "gen/msg_generated"; import { assetSourceCode } from "./assets"; -import { libdeno } from "./libdeno"; import * as os from "./os"; import { CodeProvider } from "./runner"; -import { RawSourceMap } from "./types"; import { assert, log, notImplemented } from "./util"; const EOL = "\n"; @@ -71,7 +69,7 @@ export class ModuleMetaData implements ts.IScriptSnapshot { public readonly mediaType: MediaType, public readonly sourceCode: SourceCode = "", public outputCode: OutputCode = "", - public sourceMap: SourceMap | RawSourceMap = "" + public sourceMap: SourceMap = "" ) { if (outputCode !== "" || fileName.endsWith(".d.ts")) { this.scriptVersion = "1"; @@ -131,8 +129,6 @@ export class Compiler ContainingFile, Map<ModuleSpecifier, ModuleFileName> >(); - // Keep track of state of the last module requested via `getGeneratedContents` - private _lastModule: ModuleMetaData | undefined; // A reference to the log utility, so it can be monkey patched during testing private _log = log; // A map of module file names to module meta data @@ -369,19 +365,15 @@ export class Compiler moduleMetaData.outputCode = `${ outputFile.text }\n//# sourceURL=${fileName}`; - moduleMetaData.sourceMap = JSON.parse(sourceMapFile.text); + moduleMetaData.sourceMap = sourceMapFile.text; } moduleMetaData.scriptVersion = "1"; - const sourceMap = - moduleMetaData.sourceMap === "string" - ? moduleMetaData.sourceMap - : JSON.stringify(moduleMetaData.sourceMap); this._os.codeCache( fileName, sourceCode, moduleMetaData.outputCode, - sourceMap + moduleMetaData.sourceMap ); return moduleMetaData.outputCode; } @@ -398,36 +390,10 @@ export class Compiler } /** Given a fileName, return what was generated by the compiler. */ - getGeneratedContents = (fileName: string): string | RawSourceMap => { - this._log("compiler.getGeneratedContents", fileName); - if (fileName === "gen/bundle/main.js") { - assert(libdeno.mainSource.length > 0); - return libdeno.mainSource; - } else if (fileName === "main.js.map") { - return libdeno.mainSourceMap; - } else if (fileName === "deno_main.js") { - return ""; - } else if (!fileName.endsWith(".map")) { - const moduleMetaData = this._moduleMetaDataMap.get(fileName); - if (!moduleMetaData) { - this._lastModule = undefined; - return ""; - } - this._lastModule = moduleMetaData; - return moduleMetaData.outputCode; - } else { - if (this._lastModule && this._lastModule.sourceMap) { - // Assuming the the map will always be asked for after the source - // code. - const { sourceMap } = this._lastModule; - this._lastModule = undefined; - return sourceMap; - } else { - // Errors thrown here are caught by source-map. - throw new Error(`Unable to find source map: "${fileName}"`); - } - } - }; + getGeneratedSourceMap(fileName: string): string { + const moduleMetaData = this._moduleMetaDataMap.get(fileName); + return moduleMetaData ? moduleMetaData.sourceMap : ""; + } /** Get the output code for a module based on its filename. A call to * `.getFilename()` should occur before attempting to get the output code as |