microsoft / microsoft/TypeScript
Named Tuple elements should allow reserved words as their names
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ả
Bug Report
🔎 Search Terms
tuple elements label reserved word
named tuple elements
🕗 Version & Regression Information
- This is the behavior in every version I tried, and I reviewed the FAQ for entries about "Common "Bugs" That Aren't Bugs"
⏯ Playground Link
Playground link with relevant code
💻 Code
type x = [if: any]
// but some keywords are allowed, e.g.
type y = [void: any]
🙁 Actual behavior
Unused label.
'any' only refers to a type, but is being used as a value here.
Type expected.
'(' expected.
Unexpected keyword or identifier.
Declaration or statement expected.
🙂 Expected behavior
No errors. As a label it should allow any identifiers, including reserved words.
👩💻 Possible solution
Although parseTupleElementNameOrTupleElementType allows any identifier as its name:
before it is invoked, the isListElement requires a tuple member start a type:
This is no longer true after we support named tuple member after 4.0, which should start with any valid identifiers / keywords. Because isListElement returns false, the parser does not parse them as tuple elements, which results to confusing parsing errors.
We can create a new ParsingContext for named tuple members, and returns token() === SyntaxKind.CommaToken || tokenIsIdentifierOrKeyword(token()) in isListElement.
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 trong src/compiler/parser.ts tại isListElement và parseTupleElementNameOrTupleElementType, sử dụng mã Playground được liên kết làm trường hợp tái hiện. Theo dõi cách các thành viên tuple có tên bắt đầu bằng một từ dành riêng được phân loại, sau đó thêm một regression test bao quát ví dụ và xác minh rằng nó không tạo ra lỗi phân tích cú pháp.
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
- 50/100