Skip to content

Commit 055a07e

Browse files
authored
Check for parse errors in emitted JS (#32009)
1 parent 3765651 commit 055a07e

File tree

2 files changed

+19
-4
lines changed

2 files changed

+19
-4
lines changed

src/harness/harness.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1311,6 +1311,13 @@ namespace Harness {
13111311
if (jsCode.length && jsCode.charCodeAt(jsCode.length - 1) !== ts.CharacterCodes.lineFeed) {
13121312
jsCode += "\r\n";
13131313
}
1314+
if (!result.diagnostics.length && !ts.endsWith(file.file, ts.Extension.Json)) {
1315+
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);
1316+
if (ts.length(fileParseResult.parseDiagnostics)) {
1317+
jsCode += getErrorBaseline([file.asTestFile()], fileParseResult.parseDiagnostics);
1318+
return;
1319+
}
1320+
}
13141321
jsCode += fileOutput(file, harnessSettings);
13151322
});
13161323

tests/baselines/reference/emitBOM.js

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,18 @@
22
// JS and d.ts output should have a BOM but not the sourcemap
33
var x;
44

5-
//// [emitBOM.js]
6-
// JS and d.ts output should have a BOM but not the sourcemap
7-
var x;
8-
//# sourceMappingURL=emitBOM.js.map
5+
tests/cases/compiler/emitBOM.js(1,2): error TS1127: Invalid character.
6+
tests/cases/compiler/emitBOM.js(1,3): error TS1127: Invalid character.
7+
8+
9+
==== tests/cases/compiler/emitBOM.js (2 errors) ====
10+
// JS and d.ts output should have a BOM but not the sourcemap
11+
12+
!!! error TS1127: Invalid character.
13+
14+
!!! error TS1127: Invalid character.
15+
var x;
16+
//# sourceMappingURL=emitBOM.js.map
917

1018
//// [emitBOM.d.ts]
1119
declare var x: any;

0 commit comments

Comments
 (0)