-
Notifications
You must be signed in to change notification settings - Fork 12.8k
Some private identifier errors are duplicated and uninformative #46824
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
Comments
Hi @sandersn, can I try to solve this one? |
Go ahead; let me know if you need any help. |
Sorry, it took me a while to understand the setup and flow of the project. From the issue, I assume you want to remove the "Cannot find name '#fiel'" when there is: From what I understand, the // Code reference
function checkGrammarPrivateIdentifierExpression(privId: PrivateIdentifier): boolean {
if (!getContainingClass(privId)) {
return grammarErrorOnNode(privId, Diagnostics.Private_identifiers_are_not_allowed_outside_class_bodies);
}
if (!isExpressionNode(privId)) {
return grammarErrorOnNode(privId, Diagnostics.Private_identifiers_are_only_allowed_in_class_bodies_and_may_only_be_used_as_part_of_a_class_member_declaration_property_access_or_on_the_left_hand_side_of_an_in_expression);
}
if (!getSymbolForPrivateIdentifierExpression(privId)) {
return grammarErrorOnNode(privId, Diagnostics.Cannot_find_name_0, idText(privId));
}
return false;
} |
Having thought about it a little more, I think I'd like to see "Property '#fiel' does not exist on type 'any'. for the first error and The left-hand side of a 'for...in' statement must be a variable or a property access. for the second. For the first error, the check for "cannot find name {0}" in checkGrammarPrivateIdentifierExpression needs to also check that |
Thanks, it's pretty clear now. I'll try to send a PR tomorrow. |
Conflict between microsoft#47018 and microsoft#46824, both of which changed the behaviour of private fields.
From privateNameInInExpression.errors.txt:
Expected: One error on each line of code: "Cannot find name '#fiel'" and "The left-hand side of a 'for...in' statement must be a variable or property access."
Actual: Two errors on each line.
The cause is that
checkGrammarPrivateIdentifierExpression
does not check whether other errors might apply. From my most recent read of it, I think only the first error is actually valuable, and that the "Cannot find name '#fiel'" error can be issued elsewhere. It's not really a grammatical error in any case -- it's likely just issued there because the ES spec refers to these errors as syntactic.The text was updated successfully, but these errors were encountered: