diff options
Diffstat (limited to 'js/v8_source_maps.ts')
-rw-r--r-- | js/v8_source_maps.ts | 20 |
1 files changed, 17 insertions, 3 deletions
diff --git a/js/v8_source_maps.ts b/js/v8_source_maps.ts index 956ffbe82..d5feeb1c0 100644 --- a/js/v8_source_maps.ts +++ b/js/v8_source_maps.ts @@ -1,7 +1,15 @@ // Copyright 2014 Evan Wallace // Copyright 2018 the Deno authors. All rights reserved. MIT license. // Originated from source-map-support but has been heavily modified for deno. + +// Because NodeJS.CallSite and Error.prepareStackTrace are used we add a +// dependency on the Node types. +// TODO(ry) Ideally this triple slash directive should be removed as we only +// need CallSite and Error.prepareStackTrace but nothing else. +/// <reference types="node" /> + import { SourceMapConsumer, MappedPosition } from "source-map"; +import { RawSourceMap } from "source-map"; import * as base64 from "base64-js"; import { arrayToStr } from "./util"; @@ -24,7 +32,7 @@ interface Position { line: number; } -type GetGeneratedContentsCallback = (fileName: string) => string; +type GetGeneratedContentsCallback = (fileName: string) => string | RawSourceMap; let getGeneratedContents: GetGeneratedContentsCallback; @@ -190,13 +198,16 @@ function loadConsumer(source: string): SourceMapConsumer { if (!code) { return null; } + if (typeof code !== "string") { + throw new Error("expected string"); + } let sourceMappingURL = retrieveSourceMapURL(code); if (!sourceMappingURL) { throw Error("No source map?"); } - let sourceMapData: string; + let sourceMapData: string | RawSourceMap; if (reSourceMap.test(sourceMappingURL)) { // Support source map URL as a data url const rawData = sourceMappingURL.slice(sourceMappingURL.indexOf(",") + 1); @@ -209,8 +220,11 @@ function loadConsumer(source: string): SourceMapConsumer { sourceMapData = getGeneratedContents(sourceMappingURL); } + const rawSourceMap = + typeof sourceMapData === "string" + ? JSON.parse(sourceMapData) + : sourceMapData; //console.log("sourceMapData", sourceMapData); - const rawSourceMap = JSON.parse(sourceMapData); consumer = new SourceMapConsumer(rawSourceMap); consumers.set(source, consumer); } |