diff --git a/src/compiler/sys.ts b/src/compiler/sys.ts index 9c3972b275..f3973e852c 100644 --- a/src/compiler/sys.ts +++ b/src/compiler/sys.ts @@ -8,6 +8,7 @@ namespace ts { args: string[]; newLine: string; useCaseSensitiveFileNames: boolean; + /*@internal*/ developmentMode?: boolean; write(s: string): void; readFile(path: string, encoding?: string): string; writeFile(path: string, data: string, writeByteOrderMark?: boolean): void; @@ -22,6 +23,7 @@ namespace ts { readDirectory(path: string, extension?: string, exclude?: string[]): string[]; getMemoryUsage?(): number; exit(exitCode?: number): void; + /*@internal*/ tryEnableSourceMapsForHost?(): void; } interface WatchedFile { @@ -494,6 +496,7 @@ namespace ts { args: process.argv.slice(2), newLine: _os.EOL, useCaseSensitiveFileNames: useCaseSensitiveFileNames, + developmentMode: /^development$/i.test(String(process.env.NODE_ENV)), write(s: string): void { process.stdout.write(s); }, @@ -564,6 +567,14 @@ namespace ts { }, exit(exitCode?: number): void { process.exit(exitCode); + }, + tryEnableSourceMapsForHost() { + try { + require("source-map-support").install(); + } + catch (e) { + // Could not enable source maps. + } } }; } diff --git a/src/compiler/tsc.ts b/src/compiler/tsc.ts index 889810bebe..398c87aab2 100644 --- a/src/compiler/tsc.ts +++ b/src/compiler/tsc.ts @@ -777,4 +777,8 @@ namespace ts { } } +if (ts.sys.developmentMode && ts.sys.tryEnableSourceMapsForHost) { + ts.sys.tryEnableSourceMapsForHost(); +} + ts.executeCommandLine(ts.sys.args);