diff --git a/src/harness/compilerRunner.ts b/src/harness/compilerRunner.ts
index 70c6fdac329..327932f3667 100644
--- a/src/harness/compilerRunner.ts
+++ b/src/harness/compilerRunner.ts
@@ -170,7 +170,7 @@ class CompilerBaselineRunner extends RunnerBase {
});
it("Correct Sourcemap output for " + fileName, () => {
- Harness.Compiler.doSourcemapBaseline(justName, options, result);
+ Harness.Compiler.doSourcemapBaseline(justName, options, result, harnessSettings);
});
it("Correct type/symbol baselines for " + fileName, () => {
diff --git a/src/harness/harness.ts b/src/harness/harness.ts
index 57ee46299b5..1173576f0c7 100644
--- a/src/harness/harness.ts
+++ b/src/harness/harness.ts
@@ -1554,7 +1554,7 @@ namespace Harness {
return file.writeByteOrderMark ? "\u00EF\u00BB\u00BF" : "";
}
- export function doSourcemapBaseline(baselinePath: string, options: ts.CompilerOptions, result: CompilerResult) {
+ export function doSourcemapBaseline(baselinePath: string, options: ts.CompilerOptions, result: CompilerResult, harnessSettings: Harness.TestCaseParser.CompilerSettings) {
if (options.inlineSourceMap) {
if (result.sourceMaps.length > 0) {
throw new Error("No sourcemap files should be generated if inlineSourceMaps was set.");
@@ -1576,10 +1576,8 @@ namespace Harness {
}
let sourceMapCode = "";
- for (let i = 0; i < result.sourceMaps.length; i++) {
- sourceMapCode += "//// [" + ts.getBaseFileName(result.sourceMaps[i].fileName) + "]\r\n";
- sourceMapCode += getByteOrderMarkText(result.sourceMaps[i]);
- sourceMapCode += result.sourceMaps[i].code;
+ for (const sourceMap of result.sourceMaps) {
+ sourceMapCode += fileOutput(sourceMap, harnessSettings);
}
return sourceMapCode;
@@ -1606,18 +1604,13 @@ namespace Harness {
let jsCode = "";
for (const file of result.files) {
- const fileName = harnessSettings["fullEmitPaths"] ? file.fileName : ts.getBaseFileName(file.fileName);
- jsCode += "//// [" + fileName + "]\r\n";
- jsCode += getByteOrderMarkText(file);
- jsCode += file.code;
+ jsCode += fileOutput(file, harnessSettings);
}
if (result.declFilesCode.length > 0) {
jsCode += "\r\n\r\n";
- for (let i = 0; i < result.declFilesCode.length; i++) {
- jsCode += "//// [" + ts.getBaseFileName(result.declFilesCode[i].fileName) + "]\r\n";
- jsCode += getByteOrderMarkText(result.declFilesCode[i]);
- jsCode += result.declFilesCode[i].code;
+ for (const declFile of result.declFilesCode) {
+ jsCode += fileOutput(declFile, harnessSettings);
}
}
@@ -1642,6 +1635,11 @@ namespace Harness {
});
}
+ function fileOutput(file: GeneratedFile, harnessSettings: Harness.TestCaseParser.CompilerSettings): string {
+ const fileName = harnessSettings["fullEmitPaths"] ? file.fileName : ts.getBaseFileName(file.fileName);
+ return "//// [" + fileName + "]\r\n" + getByteOrderMarkText(file) + file.code;
+ }
+
export function collateOutputs(outputFiles: Harness.Compiler.GeneratedFile[]): string {
// Collect, test, and sort the fileNames
outputFiles.sort((a, b) => ts.compareStrings(cleanName(a.fileName), cleanName(b.fileName)));
diff --git a/tests/baselines/reference/commonSourceDirectory.js b/tests/baselines/reference/commonSourceDirectory.js
index 5299095ae74..1a863dbecbd 100644
--- a/tests/baselines/reference/commonSourceDirectory.js
+++ b/tests/baselines/reference/commonSourceDirectory.js
@@ -23,3 +23,7 @@ x + y;
var foo_1 = require("foo");
var bar_1 = require("bar");
foo_1.x + bar_1.y;
+//# sourceMappingURL=/app/myMapRoot/index.js.map
+
+//// [/app/bin/index.d.ts]
+///
diff --git a/tests/baselines/reference/commonSourceDirectory.js.map b/tests/baselines/reference/commonSourceDirectory.js.map
new file mode 100644
index 00000000000..8e3f925eee9
--- /dev/null
+++ b/tests/baselines/reference/commonSourceDirectory.js.map
@@ -0,0 +1,2 @@
+//// [/app/bin/index.js.map]
+{"version":3,"file":"index.js","sourceRoot":"/app/mySourceRoot/","sources":["index.ts"],"names":[],"mappings":";AAAA,yCAAyC;AACzC,2BAAwB;AACxB,2BAAwB;AACxB,OAAC,GAAG,OAAC,CAAC"}
\ No newline at end of file
diff --git a/tests/baselines/reference/commonSourceDirectory.sourcemap.txt b/tests/baselines/reference/commonSourceDirectory.sourcemap.txt
new file mode 100644
index 00000000000..ac198eaf02c
--- /dev/null
+++ b/tests/baselines/reference/commonSourceDirectory.sourcemap.txt
@@ -0,0 +1,58 @@
+===================================================================
+JsFile: index.js
+mapUrl: /app/myMapRoot/index.js.map
+sourceRoot: /app/mySourceRoot/
+sources: index.ts
+===================================================================
+-------------------------------------------------------------------
+emittedFile:/app/bin/index.js
+sourceFile:index.ts
+-------------------------------------------------------------------
+>>>"use strict";
+>>>///
+1 >
+2 >^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+1 >
+2 >///
+1 >Emitted(2, 1) Source(1, 1) + SourceIndex(0)
+2 >Emitted(2, 42) Source(1, 42) + SourceIndex(0)
+---
+>>>var foo_1 = require("foo");
+1 >
+2 >^^^^^^^^^^^^^^^^^^^^^^^^^^^
+3 > ^->
+1 >
+ >
+2 >import { x } from "foo";
+1 >Emitted(3, 1) Source(2, 1) + SourceIndex(0)
+2 >Emitted(3, 28) Source(2, 25) + SourceIndex(0)
+---
+>>>var bar_1 = require("bar");
+1->
+2 >^^^^^^^^^^^^^^^^^^^^^^^^^^^
+1->
+ >
+2 >import { y } from "bar";
+1->Emitted(4, 1) Source(3, 1) + SourceIndex(0)
+2 >Emitted(4, 28) Source(3, 25) + SourceIndex(0)
+---
+>>>foo_1.x + bar_1.y;
+1 >
+2 >^^^^^^^
+3 > ^^^
+4 > ^^^^^^^
+5 > ^
+6 > ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^->
+1 >
+ >
+2 >x
+3 > +
+4 > y
+5 > ;
+1 >Emitted(5, 1) Source(4, 1) + SourceIndex(0)
+2 >Emitted(5, 8) Source(4, 2) + SourceIndex(0)
+3 >Emitted(5, 11) Source(4, 5) + SourceIndex(0)
+4 >Emitted(5, 18) Source(4, 6) + SourceIndex(0)
+5 >Emitted(5, 19) Source(4, 7) + SourceIndex(0)
+---
+>>>//# sourceMappingURL=/app/myMapRoot/index.js.map
\ No newline at end of file
diff --git a/tests/cases/compiler/commonSourceDirectory.ts b/tests/cases/compiler/commonSourceDirectory.ts
index 930f922e10d..9baa27431a3 100644
--- a/tests/cases/compiler/commonSourceDirectory.ts
+++ b/tests/cases/compiler/commonSourceDirectory.ts
@@ -21,6 +21,10 @@ x + y;
{
"compilerOptions": {
"outDir": "bin",
- "typeRoots": ["../types"]
+ "typeRoots": ["../types"],
+ "sourceMap": true,
+ "mapRoot": "myMapRoot",
+ "sourceRoot": "mySourceRoot",
+ "declaration": true
}
}