Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Throwing SyntaxError if a parsed source file is syntactically incorrect #202

Merged
merged 2 commits into from
Jan 27, 2025

Conversation

arodionov
Copy link
Contributor

If a source file has syntax errors, the ParseError is generated, and the file is skipped from parsing.

Syntactically, the check is based on the TS compiler function ts.getPreEmitDiagnostics.
There is a list of error codes that can be ignored or added.

If a source file has syntax errors, the ParseError is generated, and the file is skipped from parsing.
Syntactically check is based on TS compiler function `ts.getPreEmitDiagnostics`.
There are a list of error codes, that can be ignored or added.
@arodionov arodionov merged commit 473fa06 into main Jan 27, 2025
1 check passed
@arodionov arodionov deleted the syntax-errors branch January 27, 2025 19:50
const syntaxErrors = checkSyntaxErrors(program, sourceFile);
if (syntaxErrors.length > 0) {
syntaxErrors.forEach(
e => result.push(ParseError.build(this, input, relativeTo, ctx, new SyntaxError(`Compiler error: ${e[0]} [${e[1]}]`), null))
Copy link
Contributor

Choose a reason for hiding this comment

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

Could this end up creating multiple ParseErrors for one source file?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, there can be many ParseErrors for one source file

// Other critical errors
]);

const excludedCodes = new Set([1039, 1064, 1101, 1107, 1111, 1155, 1166, 1170, 1183, 1203, 1207, 1215, 1238, 1239, 1240, 1241, 1244, 1250,
Copy link
Contributor

Choose a reason for hiding this comment

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

Are there constants with readable names for all these codes?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I can put here the code description.
The full list is available here https://github.com/microsoft/TypeScript/blob/main/src/compiler/diagnosticMessages.json

# for free to join this conversation on GitHub. Already have an account? # to comment
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

2 participants