microsoft / microsoft/TypeScript
`for (const x in #b)` is allowed
Chưa có ai nhận issue này.
- Ngôn ngữ chính
- Go
- Star
- 111k
- Fork
- 14.4k
- Merge trung bình
- 1 ngày 19 giờ
- Pull request đã merge (30 ngày)
- 117
Mô tả
🔎 Search Terms
Private identifier, for...in
🕗 Version & Regression Information
- This changed between versions 4.5.5 and 4.6.4
⏯ Playground Link
💻 Code
class A {
#b() {
for (const a in #b) {
}
}
}
🙁 Actual behavior
No errors
🙂 Expected behavior
Error: 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
Additional information about the issue
Noticed this while working on https://github.com/typescript-eslint/typescript-eslint/pull/9232. There's a very suspicious condition in code: https://github.com/microsoft/TypeScript/blob/5a4134470128a062a8297f404dfb3321f8f55798/src/compiler/checker.ts#L33699
function checkGrammarPrivateIdentifierExpression(privId: PrivateIdentifier): boolean {
if (!getContainingClass(privId)) {
return grammarErrorOnNode(privId, Diagnostics.Private_identifiers_are_not_allowed_outside_class_bodies);
}
if (!isForInStatement(privId.parent)) {
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);
}
const isInOperation = isBinaryExpression(privId.parent) && privId.parent.operatorToken.kind === SyntaxKind.InKeyword;
if (!getSymbolForPrivateIdentifierExpression(privId) && !isInOperation) {
return grammarErrorOnNode(privId, Diagnostics.Cannot_find_name_0, idText(privId));
}
}
return false;
}
I don't know what isForInStatement is supposed to do there. I was unable to find the commit that introduced this—git blame took me to #44648 but that didn't have this condition.
Hướng dẫn đóng góp
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Hướng nghiên cứu
Bắt đầu với lớp đã tái hiện trong liên kết Playground và kiểm tra checkGrammarPrivateIdentifierExpression trong src/compiler/checker.ts, xung quanh điều kiện isForInStatement. Xác nhận chẩn đoán hiện được tạo ra cho for (const a in #b) và so sánh với lỗi private-identifier dự kiến. Được xem là hoàn tất khi dạng không hợp lệ bị từ chối với chẩn đoán dự kiến và hành vi này được bao phủ bởi các bài kiểm thử hồi quy của compiler.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Đánh giá
- Công nghệ
- typescript
- Lĩnh vực
- compilers
- Loại issue
- Lỗi
- Độ khó
- 3/5
- Thời gian dự kiến
- 1-2 ngày
- Mức độ hoạt động
- Đình trệ
- Độ rõ ràng
- Đặc tả rõ ràng
- Mức phù hợp với người mới
- 58/100