Skip to content

Commit a4fc202

Browse files
committed
fix(46824): remove duplicate private identifier errors
1 parent d417058 commit a4fc202

File tree

1 file changed

+11
-5
lines changed

1 file changed

+11
-5
lines changed

src/compiler/checker.ts

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28224,12 +28224,18 @@ namespace ts {
2822428224
if (!getContainingClass(privId)) {
2822528225
return grammarErrorOnNode(privId, Diagnostics.Private_identifiers_are_not_allowed_outside_class_bodies);
2822628226
}
28227-
if (!isExpressionNode(privId)) {
28228-
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);
28229-
}
28230-
if (!getSymbolForPrivateIdentifierExpression(privId)) {
28231-
return grammarErrorOnNode(privId, Diagnostics.Cannot_find_name_0, idText(privId));
28227+
28228+
if (!isForInStatement(privId.parent)) {
28229+
if (!isExpressionNode(privId)) {
28230+
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);
28231+
}
28232+
28233+
const isInOperation = isBinaryExpression(privId.parent) && privId.parent.operatorToken.kind === SyntaxKind.InKeyword;
28234+
if (!getSymbolForPrivateIdentifierExpression(privId) && !isInOperation) {
28235+
return grammarErrorOnNode(privId, Diagnostics.Cannot_find_name_0, idText(privId));
28236+
}
2823228237
}
28238+
2823328239
return false;
2823428240
}
2823528241

0 commit comments

Comments
 (0)