Skip to content

Check for parse errors in emitted JS #32009

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 1 commit into from
Jul 1, 2019
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
7 changes: 7 additions & 0 deletions src/harness/harness.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});

Expand Down
16 changes: 12 additions & 4 deletions tests/baselines/reference/emitBOM.js
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@rbuckton you know what's up with the BOM here? I suspect it's actually an issue with the test harness not roundtripping the BOM correctly (maybe by not reading the output string with the correct encoding) and not a parse/emit bug, but I can't be sure.


!!! error TS1127: Invalid character.
var x;
//# sourceMappingURL=emitBOM.js.map

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