Skip to content

Commit efe76c0

Browse files
committed
Check for parse errors in emitted JS
1 parent f2735b5 commit efe76c0

File tree

3 files changed

+35
-8
lines changed

3 files changed

+35
-8
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/constEnum4.js

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,19 @@ else
77
const enum C { }
88

99

10-
//// [constEnum4.js]
11-
if (1)
12-
else if (2)
13-
else
10+
tests/cases/conformance/constEnums/constEnum4.js(2,1): error TS1109: Expression expected.
11+
tests/cases/conformance/constEnums/constEnum4.js(3,1): error TS1109: Expression expected.
12+
tests/cases/conformance/constEnums/constEnum4.js(3,5): error TS1109: Expression expected.
13+
14+
15+
==== tests/cases/conformance/constEnums/constEnum4.js (3 errors) ====
16+
if (1)
17+
else if (2)
18+
~~~~
19+
!!! error TS1109: Expression expected.
20+
else
21+
~~~~
22+
!!! error TS1109: Expression expected.
23+
24+
!!! error TS1109: Expression expected.
25+

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)