From 2c65292119d13b880ad57783dda434147b6f6980 Mon Sep 17 00:00:00 2001 From: Ryan Dahl Date: Sat, 19 May 2018 07:06:23 -0400 Subject: [PATCH] Source map support. Partially working. --- main.ts | 24 ++++++++++++++++++++++++ package.json | 2 ++ runtime.ts | 15 ++++++++------- testdata/007_stack_trace.ts | 11 +++++++++++ yarn.lock | 19 ++++++++++++++++++- 5 files changed, 63 insertions(+), 8 deletions(-) create mode 100644 testdata/007_stack_trace.ts diff --git a/main.ts b/main.ts index ac0b4d3292..9140d20ff6 100644 --- a/main.ts +++ b/main.ts @@ -3,6 +3,29 @@ import "./util"; import * as runtime from "./runtime"; import * as timers from "./timers"; import * as util from "./util"; +import * as sourceMap from "source-map-support"; + +function retrieveFileForSourceMap(path: string): string { + util.log("retrieveFileForSourceMap", path); + throw Error("implemtn me"); +} + +function retrieveSourceMap(source: string): sourceMap.UrlAndMap { + util.log("retrieveSourceMap", source); + throw Error("implemtn me"); + //return { url, map } +} + +// TODO handleUncaughtExceptions +sourceMap.install({ + //handleUncaughtExceptions: true, + environment: "node", + retrieveFile: retrieveFileForSourceMap, + hookRequire: false, + overrideRetrieveSourceMap: true, + overrideRetrieveFile: true, + retrieveSourceMap +}); // To control internal logging output // Set with the -debug command-line flag. @@ -11,6 +34,7 @@ export let debug = false; function start(cwd: string, argv: string[], debugFlag: boolean): void { debug = debugFlag; util.log("start", { cwd, argv, debugFlag }); + const inputFn = argv[0]; const mod = runtime.resolveModule(inputFn, cwd + "/"); mod.compileAndRun(); diff --git a/package.json b/package.json index 60bdc8a053..df7ef042e6 100644 --- a/package.json +++ b/package.json @@ -5,9 +5,11 @@ "fmt": "prettier --write *.ts* *.js *.json" }, "devDependencies": { + "@types/source-map-support": "^0.4.0", "http-server": "^0.11.1", "parcel-bundler": "^1.8.1", "protobufjs": "^6.8.6", + "source-map-support": "^0.5.6", "tslint": "^5.10.0", "typescript": "^2.8.3" }, diff --git a/runtime.ts b/runtime.ts index 7d6633ca9c..1b1e309b5e 100644 --- a/runtime.ts +++ b/runtime.ts @@ -14,6 +14,10 @@ import "./url"; const EOL = "\n"; +// tslint:disable-next-line:no-any +type AmdFactory = (...args: any[]) => undefined | object; +type AmdDefine = (deps: string[], factory: AmdFactory) => void; + // This class represents a module. We call it FileModule to make it explicit // that each module represents a single file. // Access to FileModule instances should only be done thru the static method @@ -66,10 +70,6 @@ export class FileModule { } } -// tslint:disable-next-line:no-any -type AmdFactory = (...args: any[]) => undefined | object; -type AmdDefine = (deps: string[], factory: AmdFactory) => void; - export function makeDefine(fileName: string): AmdDefine { const localDefine = (deps: string[], factory: AmdFactory): void => { const localRequire = (x: string) => { @@ -122,6 +122,7 @@ function resolveModuleName( function execute(fileName: string, outputCode: string): void { util.assert(outputCode && outputCode.length > 0); util._global["define"] = makeDefine(fileName); + outputCode += "\n//# sourceURL=" + fileName; util.globalEval(outputCode); util._global["define"] = null; } @@ -131,12 +132,12 @@ class Compiler { options: ts.CompilerOptions = { allowJs: true, module: ts.ModuleKind.AMD, - outDir: "$deno$" + outDir: "$deno$", + inlineSourceMap: true, + inlineSources: true }; /* allowJs: true, - inlineSourceMap: true, - inlineSources: true, module: ts.ModuleKind.AMD, noEmit: false, outDir: '$deno$', diff --git a/testdata/007_stack_trace.ts b/testdata/007_stack_trace.ts new file mode 100644 index 0000000000..2424bf9497 --- /dev/null +++ b/testdata/007_stack_trace.ts @@ -0,0 +1,11 @@ +function foo() { + throw Error("bad"); +} + +function bar() { + foo() +} + +console.log("before"); +bar() +console.log("after"); diff --git a/yarn.lock b/yarn.lock index 52e93859b5..e7e3e6929b 100644 --- a/yarn.lock +++ b/yarn.lock @@ -49,10 +49,20 @@ version "3.0.32" resolved "https://registry.yarnpkg.com/@types/long/-/long-3.0.32.tgz#f4e5af31e9e9b196d8e5fca8a5e2e20aa3d60b69" +"@types/node@*": + version "10.1.2" + resolved "https://registry.yarnpkg.com/@types/node/-/node-10.1.2.tgz#1b928a0baa408fc8ae3ac012cc81375addc147c6" + "@types/node@^8.9.4": version "8.10.14" resolved "https://registry.yarnpkg.com/@types/node/-/node-8.10.14.tgz#a24767cfa22023f1bf7e751c0ead56a14c07ed45" +"@types/source-map-support@^0.4.0": + version "0.4.0" + resolved "https://registry.yarnpkg.com/@types/source-map-support/-/source-map-support-0.4.0.tgz#a62a1866614af68c888173c001481f242aaf148b" + dependencies: + "@types/node" "*" + abbrev@1: version "1.1.1" resolved "https://registry.yarnpkg.com/abbrev/-/abbrev-1.1.1.tgz#f8f2c887ad10bf67f634f005b6987fed3179aac8" @@ -3317,11 +3327,18 @@ source-map-support@^0.4.15: dependencies: source-map "^0.5.6" +source-map-support@^0.5.6: + version "0.5.6" + resolved "https://registry.yarnpkg.com/source-map-support/-/source-map-support-0.5.6.tgz#4435cee46b1aab62b8e8610ce60f788091c51c13" + dependencies: + buffer-from "^1.0.0" + source-map "^0.6.0" + source-map-url@^0.4.0: version "0.4.0" resolved "https://registry.yarnpkg.com/source-map-url/-/source-map-url-0.4.0.tgz#3e935d7ddd73631b97659956d55128e87b5084a3" -source-map@0.6.1, source-map@^0.6.1, source-map@~0.6.1: +source-map@0.6.1, source-map@^0.6.0, source-map@^0.6.1, source-map@~0.6.1: version "0.6.1" resolved "https://registry.yarnpkg.com/source-map/-/source-map-0.6.1.tgz#74722af32e9614e9c287a8d0bbde48b5e2f1a263"