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

已关闭 适合新手
#65,107 1 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

维护者通常 1 天内回复

还没有人认领这个 Issue。

评估

难度
2/5
预计耗时
1-3 小时
新手友好度
62/100
Issue 类型
缺陷
描述清晰度
描述清楚
活跃度
活跃
技术栈
go, typescript
领域
compilers

调研方向

该缺陷位于 tsc/internal/scanner/scanner.go 中的 isConflictMarkerTrivia,约第 2422–2425 行,其中行首回退逻辑解码的是 text[:pos-2] 而非 text[:pos]。请先在字面 U+2028 出现在 <<<<<<< HEAD 之前的情况下复现,并确认出现的是 TS1109 而非 TS1185。修复方法是从 text[:pos] 解码前一个 rune;当 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 小时
30 天内合并 PR
136

环境准备

在 Codespaces 中打开

在浏览器里用你自己的 GitHub 账号启动这个项目的开发容器。

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

microsoft/TypeScript 的其他 Issue

查看 microsoft/TypeScript 的全部 Issue

相似的 Issue

更多 Go Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。