Skip to content
This repository was archived by the owner on May 12, 2025. It is now read-only.

Commit de3ab04

Browse files
authored
Pack several compiler errors into one ParseError (#203)
1 parent 473fa06 commit de3ab04

File tree

2 files changed

+4
-4
lines changed

2 files changed

+4
-4
lines changed

openrewrite/src/javascript/parser.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -156,9 +156,8 @@ export class JavaScriptParser extends Parser {
156156

157157
const syntaxErrors = checkSyntaxErrors(program, sourceFile);
158158
if (syntaxErrors.length > 0) {
159-
syntaxErrors.forEach(
160-
e => result.push(ParseError.build(this, input, relativeTo, ctx, new SyntaxError(`Compiler error: ${e[0]} [${e[1]}]`), null))
161-
);
159+
let errors = syntaxErrors.map(e => `${e[0]} [${e[1]}]`).join('; ');
160+
result.push(ParseError.build(this, input, relativeTo, ctx, new SyntaxError(`Compiler error(s) for ${sourceFile.fileName}: ${errors}`), null))
162161
continue;
163162
}
164163

openrewrite/src/javascript/parserUtils.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,7 @@ export function checkSyntaxErrors(program: ts.Program, sourceFile: ts.SourceFile
203203
if (e.file) {
204204
let {line, character} = ts.getLineAndCharacterOfPosition(e.file, e.start!);
205205
let message = ts.flattenDiagnosticMessageText(e.messageText, "\n");
206-
errorMsg = `${e.file.fileName} (${line + 1},${character + 1}): ${message}`;
206+
errorMsg = `(${line + 1},${character + 1}): ${message}`;
207207
} else {
208208
errorMsg = ts.flattenDiagnosticMessageText(e.messageText, "\n");
209209
}
@@ -222,6 +222,7 @@ const additionalCriticalCodes = new Set([
222222
// Other critical errors
223223
]);
224224

225+
// errors code description available at https://github.com/microsoft/TypeScript/blob/main/src/compiler/diagnosticMessages.json
225226
const excludedCodes = new Set([1039, 1064, 1101, 1107, 1111, 1155, 1166, 1170, 1183, 1203, 1207, 1215, 1238, 1239, 1240, 1241, 1244, 1250,
226227
1251, 1252, 1253, 1254, 1308, 1314, 1315, 1324, 1329, 1335, 1338, 1340, 1343, 1344, 1345, 1355, 1360, 1378, 1432]);
227228

0 commit comments

Comments
 (0)