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
Specific diagnostic suggestions for unexpected keyword or identifier #43005
Specific diagnostic suggestions for unexpected keyword or identifier #43005
Conversation
61a4bf3
to
ec81e4d
Compare
ec81e4d
to
0c967f9
Compare
Is there any corpus of syntactically incorrect code that we could use to figure out how this changes errors? For the number of new error messages, there isn't a lot of churn in our existing tests, which makes me think our coverage isn't very good. |
@sandersn I haven't found one. Looking around at Stryker was a fun curiosity but there isn't any prior art to go off of. Is there something you'd like me to do? I can set up some sample code given parameters for what you're interested in, such as size of the test case. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A couple to take a closer look at. Looks pretty nice overall, though!
tests/baselines/reference/derivedClassSuperCallsInNonConstructorMembers.errors.txt
Outdated
Show resolved
Hide resolved
tests/baselines/reference/derivedClassSuperCallsInNonConstructorMembers.errors.txt
Show resolved
Hide resolved
tests/baselines/reference/interfacesWithPredefinedTypesAsNames.errors.txt
Outdated
Show resolved
Hide resolved
tests/baselines/reference/parserErrorRecovery_IncompleteMemberVariable2.errors.txt
Outdated
Show resolved
Hide resolved
tests/baselines/reference/parserUnterminatedGeneric2.errors.txt
Outdated
Show resolved
Hide resolved
tests/baselines/reference/templateStringInModuleName.errors.txt
Outdated
Show resolved
Hide resolved
tests/baselines/reference/templateStringInModuleName.errors.txt
Outdated
Show resolved
Hide resolved
tests/baselines/reference/parserComputedPropertyName33.errors.txt
Outdated
Show resolved
Hide resolved
@JoshuaKGoldberg I was hoping for a brainstorming session leading to serendipity. Thanks for brainstorming; maybe next time we'll hit on a great idea. I know other parsers have used fuzzers to good effect, so that might be a worthwhile thing for us to do as a standalone project. Edit Second attempt for clarity: I was asking for you (and any onlookers) to brainstorm ideas for finding syntactically incorrect program text, not with a high expectation of success, but hoping for a small chance. Which you did! Your fuzzing idea is better than I hoped for, although it's probably not worth getting it set up just for this one PR. |
I think that function name is my only nit. Otherwise this seems good to go! |
function parseSemicolonAfterPropertyName(name: PropertyName, type: TypeNode | undefined, initializer: Expression | undefined) { | ||
switch (token()) { | ||
case SyntaxKind.AtToken: | ||
parseErrorAtCurrentToken(Diagnostics.Decorators_must_precede_the_name_and_all_keywords_of_property_declarations); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should only report an error here if there's no preceding line terminator. This is valid JS:
class C {
a
b
c() {}
}
ASI inserts a ;
between a
and b
, and between b
and c()
. I would expect the same to be true for decorators:
class C {
a
@dec b
c() {}
}
This should be legal since ASI would insert a ;
between a
and @dec
, however now it is an error.
Fixes #25429
I started off by special casing the generic
';' expected
message for just the "parser sees a word instead of a semicolon" case... but that exposed a ton of test cases in the baselines where different unexpected words were equally or even more confusing with the new error message. There are some baselines that aren't strictly better in this new version but for fear of bloating this PR I tried to stay away from parser behavior changes and limit to only:Each of these errors are improvements over previous scenarios that gave a
';' expected
complaint and generally fall into one of three categories:Error messages could definitely use a round of proofreading from someone who knows better than me how to write them...