Native tsc: merge conflict markers after U+2028/U+2029 are not recognized (false TS1109 instead of TS1185)

Đã đóng Phù hợp với người mới
#65,107 1 bình luận 0 reaction 0 người được giao Xem trên GitHub

Maintainer thường phản hồi trong vòng 1 ngày

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

Đánh giá

Độ khó
2/5
Thời gian dự kiến
1-3 giờ
Mức phù hợp với người mới
62/100
Loại issue
Lỗi
Độ rõ ràng
Đặc tả rõ ràng
Mức độ hoạt động
Sôi nổi
Công nghệ
go, typescript
Lĩnh vực
compilers

Hướng nghiên cứu

Lỗi nằm ở isConflictMarkerTrivia trong tsc/internal/scanner/scanner.go, khoảng dòng 2422–2425, nơi nhánh dự phòng đầu dòng giải mã text[:pos-2] thay vì text[:pos]. Hãy bắt đầu bằng cách tái hiện với một U+2028 thực sự đặt trước <<<<<<< HEAD và xác nhận TS1109 xuất hiện thay vì TS1185. Cách sửa là giải mã rune trước đó từ text[:pos]; hoàn thành khi các trường hợp LS và PS báo TS1185 giống như trường hợp đối chứng LF/CR.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Mô tả

Won't Fix
🔎 Search Terms

merge conflict marker, TS1185, isConflictMarkerTrivia, U+2028, U+2029, line separator, paragraph separator, UTF-8

🕗 Version & Regression Information
  • This changed between classic TypeScript 5.9.3 and native tsc 7.1.0-dev
  • Verified on current main (Go / tsgo)
  • Markers after LF/CR still work; only LS/PS break recognition
⏯ Playground Link

N/A (needs a literal U+2028 / U+2029 in the source)

💻 Code
export {};
<<<<<<< HEAD

(U+2028 between {}; and <<<<<<<; same with U+2029. Also reproduces with ======= / >>>>>>>.)

tsc file.ts

Control (works on both):

export {};
<<<<<<< HEAD
🙁 Actual behavior

Native tsc treats the markers as ordinary tokens, e.g.:

error TS1109: Expression expected.

(and further cascade errors)

🙂 Expected behavior

Classic 5.9.3:

error TS1185: Merge conflict marker encountered.
Additional information about the issue

Root cause in tsc/internal/scanner/scanner.go (isConflictMarkerTrivia, ~2422–2425):

atLineStart := pos == 0 || stringutil.IsLineBreak(rune(text[pos-1]))
if !atLineStart && pos >= 2 {
    prev, _ := utf8.DecodeLastRuneInString(text[:pos-2]) // should be text[:pos]
    atLineStart = stringutil.IsLineBreak(prev)
}

After LS (E2 80 A8), text[pos-1] is 0xA8 (not a line break). The fallback decodes text[:pos-2] (ends at E2) instead of the full prior rune. Classic UTF-16 charCodeAt(pos-1) sees 0x2028 correctly.

Fix: utf8.DecodeLastRuneInString(text[:pos]).

Same UTF-8 line-break family as literal U+2028 in regex first-pass scanning.

Ngôn ngữ chính
Go
Star
112k
Fork
15.4k
Merge trung bình
3 ngày 1 giờ
Pull request đã merge (30 ngày)
136

Chuẩn bị môi trường

Mở trong Codespaces

Khởi chạy dev container của dự án ngay trên trình duyệt, bằng tài khoản GitHub của bạn.

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.

Issue khác của microsoft/TypeScript

Tất cả issue của microsoft/TypeScript

Issue tương tự

Thêm issue về Go

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.