Check for parse errors in emitted JS (#32009)

This commit is contained in:
Wesley Wigham
2019-07-01 14:15:30 -07:00
committed by GitHub
parent 3765651d82
commit 055a07ea4a
2 changed files with 19 additions and 4 deletions

View File

@@ -1311,6 +1311,13 @@ namespace Harness {
if (jsCode.length && jsCode.charCodeAt(jsCode.length - 1) !== ts.CharacterCodes.lineFeed) {
jsCode += "\r\n";
}
if (!result.diagnostics.length && !ts.endsWith(file.file, ts.Extension.Json)) {
const fileParseResult = ts.createSourceFile(file.file, file.text, options.target || ts.ScriptTarget.ES3, /*parentNodes*/ false, ts.endsWith(file.file, "x") ? ts.ScriptKind.JSX : ts.ScriptKind.JS);
if (ts.length(fileParseResult.parseDiagnostics)) {
jsCode += getErrorBaseline([file.asTestFile()], fileParseResult.parseDiagnostics);
return;
}
}
jsCode += fileOutput(file, harnessSettings);
});

View File

@@ -2,10 +2,18 @@
// JS and d.ts output should have a BOM but not the sourcemap
var x;
//// [emitBOM.js]
// JS and d.ts output should have a BOM but not the sourcemap
var x;
//# sourceMappingURL=emitBOM.js.map
tests/cases/compiler/emitBOM.js(1,2): error TS1127: Invalid character.
tests/cases/compiler/emitBOM.js(1,3): error TS1127: Invalid character.
==== tests/cases/compiler/emitBOM.js (2 errors) ====
// JS and d.ts output should have a BOM but not the sourcemap
!!! error TS1127: Invalid character.
!!! error TS1127: Invalid character.
var x;
//# sourceMappingURL=emitBOM.js.map
//// [emitBOM.d.ts]
declare var x: any;