microsoft / microsoft/TypeScript

Named Tuple elements should allow reserved words as their names

Đang mở
#45,819 0 bình luận 4 reaction 0 người được giao Xem trên GitHub

Chưa có ai nhận issue này.

Awaiting More Feedback Suggestion
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:

https://github.com/microsoft/TypeScript/blob/0af2497fecef9e41d7d0260fd37932dd33912c66/src/compiler/parser.ts#L3559

before it is invoked, the isListElement requires a tuple member start a type:

https://github.com/microsoft/TypeScript/blob/0af2497fecef9e41d7d0260fd37932dd33912c66/src/compiler/parser.ts#L2091

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

Mở hướng dẫn đóng góp

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. 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.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. 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

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.