Skip to content

Commit 6afd5c9

Browse files
author
Orta
authored
Adds a preview link to the baseline emits for sourcemaps (microsoft#37111)
1 parent 0ae938b commit 6afd5c9

File tree

144 files changed

+317
-148
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

144 files changed

+317
-148
lines changed

src/harness/harnessIO.ts

+16
Original file line numberDiff line numberDiff line change
@@ -847,12 +847,28 @@ namespace Harness {
847847
result.maps.forEach(sourceMap => {
848848
if (sourceMapCode) sourceMapCode += "\r\n";
849849
sourceMapCode += fileOutput(sourceMap, harnessSettings);
850+
if (!options.inlineSourceMap) {
851+
sourceMapCode += createSourceMapPreviewLink(sourceMap.text, result);
852+
}
850853
});
851854
}
852855
Baseline.runBaseline(baselinePath.replace(/\.tsx?/, ".js.map"), sourceMapCode);
853856
}
854857
}
855858

859+
function createSourceMapPreviewLink(sourcemap: string, result: compiler.CompilationResult) {
860+
const sourcemapJSON = JSON.parse(sourcemap);
861+
const outputJSFile = result.outputs.find(td => td.file.endsWith(sourcemapJSON.file));
862+
if (!outputJSFile) return "";
863+
864+
const sourceTDs = ts.map(sourcemapJSON.sources, (s: string) => result.inputs.find(td => td.file.endsWith(s)));
865+
const anyUnfoundSources = ts.contains(sourceTDs, /*value*/ undefined);
866+
if (anyUnfoundSources) return "";
867+
868+
const hash = "#base64," + ts.map([outputJSFile.text, sourcemap].concat(sourceTDs.map(td => td!.text)), (s) => ts.convertToBase64(decodeURIComponent(encodeURIComponent(s)))).join(",");
869+
return "\n//// https://sokra.github.io/source-map-visualization" + hash + "\n";
870+
}
871+
856872
export function doJsEmitBaseline(baselinePath: string, header: string, options: ts.CompilerOptions, result: compiler.CompilationResult, tsConfigFiles: readonly TestFile[], toBeCompiled: readonly TestFile[], otherFiles: readonly TestFile[], harnessSettings: TestCaseParser.CompilerSettings) {
857873
if (!options.noEmit && !options.emitDeclarationOnly && result.js.size === 0 && result.diagnostics.length === 0) {
858874
throw new Error("Expected at least one js file to be emitted or at least one error to be created.");

tests/baselines/reference/ES5For-of1.js.map

+2-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

tests/baselines/reference/ES5For-of13.js.map

+2-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

tests/baselines/reference/ES5For-of25.js.map

+2-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

tests/baselines/reference/ES5For-of26.js.map

+2-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

tests/baselines/reference/ES5For-of3.js.map

+2-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

tests/baselines/reference/ES5For-of33.js.map

+2-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

tests/baselines/reference/ES5For-of34.js.map

+2-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

tests/baselines/reference/ES5For-of35.js.map

+2-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

tests/baselines/reference/ES5For-of36.js.map

+2-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)