Skip to content

Adds a preview link to the baseline emits for sourcemaps #37111

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Mar 26, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions src/harness/harnessIO.ts
Original file line number Diff line number Diff line change
Expand Up @@ -847,12 +847,28 @@ namespace Harness {
result.maps.forEach(sourceMap => {
if (sourceMapCode) sourceMapCode += "\r\n";
sourceMapCode += fileOutput(sourceMap, harnessSettings);
if (!options.inlineSourceMap) {
sourceMapCode += createSourceMapPreviewLink(sourceMap.text, result);
}
});
}
Baseline.runBaseline(baselinePath.replace(/\.tsx?/, ".js.map"), sourceMapCode);
}
}

function createSourceMapPreviewLink(sourcemap: string, result: compiler.CompilationResult) {
const sourcemapJSON = JSON.parse(sourcemap);
const outputJSFile = result.outputs.find(td => td.file.endsWith(sourcemapJSON.file));
if (!outputJSFile) return "";

const sourceTDs = ts.map(sourcemapJSON.sources, (s: string) => result.inputs.find(td => td.file.endsWith(s)));
const anyUnfoundSources = ts.contains(sourceTDs, /*value*/ undefined);
if (anyUnfoundSources) return "";

const hash = "#base64," + ts.map([outputJSFile.text, sourcemap].concat(sourceTDs.map(td => td!.text)), (s) => ts.convertToBase64(decodeURIComponent(encodeURIComponent(s)))).join(",");
return "\n//// https://sokra.github.io/source-map-visualization" + hash + "\n";
}

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) {
if (!options.noEmit && !options.emitDeclarationOnly && result.js.size === 0 && result.diagnostics.length === 0) {
throw new Error("Expected at least one js file to be emitted or at least one error to be created.");
Expand Down
3 changes: 2 additions & 1 deletion tests/baselines/reference/ES5For-of1.js.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion tests/baselines/reference/ES5For-of13.js.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion tests/baselines/reference/ES5For-of25.js.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion tests/baselines/reference/ES5For-of26.js.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion tests/baselines/reference/ES5For-of3.js.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion tests/baselines/reference/ES5For-of33.js.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion tests/baselines/reference/ES5For-of34.js.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion tests/baselines/reference/ES5For-of35.js.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion tests/baselines/reference/ES5For-of36.js.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading