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

クローズ 初心者向け
#65,107 コメント 1 件 リアクション 0 件 担当者 0 名 GitHub で見る

メンテナーはふだん 1 日以内に返信

まだ誰も着手していません。

評価

難易度
2/5
見積もり時間
1〜3時間
初心者へのやさしさ
62/100
issue の種類
バグ
明瞭さ
明確に書かれている
活発さ
活発
技術スタック
go, typescript
領域
compilers

調査の方向性

バグは tsc/internal/scanner/scanner.go の isConflictMarkerTrivia(2422〜2425行目付近)にあり、行頭のフォールバックが text[:pos] の代わりに text[:pos-2] をデコードしています。まず、<<<<<<< HEAD の前にリテラルの U+2028 を置いて再現し、TS1185 ではなく TS1109 が出ることを確認してください。修正は、直前のルーンを text[:pos] からデコードすることです。LS と PS のケースが LF/CR の対照と同じく TS1185 を報告すれば完了です。

索引モデルが issue の本文から書いたものです。

説明

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.

主要言語
Go
スター
112k
フォーク
15.4k
平均マージ
3日 1時間
マージ済み PR(30日)
136

環境構築

Codespaces で開く

このプロジェクトの開発コンテナを、あなたの GitHub アカウントでブラウザ上に起動します。

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

microsoft/TypeScript のほかの issue

microsoft/TypeScript の issue をすべて見る

似ている issue

Go の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。