Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions tsc/internal/scanner/scanner.go
Original file line number Diff line number Diff line change
Expand Up @@ -2471,8 +2471,8 @@ func isConflictMarkerTrivia(text string, pos int) bool {

// Conflict markers must be at the start of a line.
atLineStart := pos == 0 || stringutil.IsLineBreak(rune(text[pos-1]))
if !atLineStart && pos >= 2 {
prev, _ := utf8.DecodeLastRuneInString(text[:pos-2])
if !atLineStart && text[pos-1] > maxAsciiCharacter {
prev, _ := utf8.DecodeLastRuneInString(text[:pos])
atLineStart = stringutil.IsLineBreak(prev)
}
if atLineStart {
Expand Down
39 changes: 39 additions & 0 deletions tsc/internal/scanner/scanner_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,45 @@ func TestScanSourceKeyword(t *testing.T) {
assert.Equal(t, s.TokenValue(), "sourceValue")
}

func TestConflictMarkerLineStart(t *testing.T) {
t.Parallel()

tests := []struct {
name string
prefix string
expected bool
}{
{name: "start of file", expected: true},
{name: "line feed", prefix: "\n", expected: true},
{name: "carriage return", prefix: "\r", expected: true},
{name: "CRLF", prefix: "\r\n", expected: true},
{name: "line separator", prefix: "\u2028", expected: true},
{name: "paragraph separator", prefix: "\u2029", expected: true},
{name: "text then line separator", prefix: "a\u2028", expected: true},
{name: "one ASCII byte", prefix: "a"},
{name: "two ASCII bytes", prefix: "ab"},
{name: "ASCII after line feed", prefix: "\nab"},
{name: "spaces after line feed", prefix: "\n "},
{name: "two byte rune after line feed", prefix: "\né"},
{name: "three byte rune after line feed", prefix: "\n€"},
{name: "four byte rune after line feed", prefix: "\n🦀"},
{name: "ASCII after line separator", prefix: "\u2028ab"},
{name: "ASCII after paragraph separator", prefix: "\u2029ab"},
{name: "invalid UTF-8 byte", prefix: "\xff"},
{name: "invalid UTF-8 after line feed", prefix: "\n\xff\xfe"},
}

for _, test := range tests {
t.Run(test.name, func(t *testing.T) {
t.Parallel()
for _, marker := range []string{"<<<<<<< x", "======= x", ">>>>>>> x", "||||||| x"} {
text := test.prefix + marker
assert.Equal(t, isConflictMarkerTrivia(text, len(test.prefix)), test.expected, "%q", text)
}
})
}
}

func TestLookupKeywordMatchesKeywordMap(t *testing.T) {
t.Parallel()
for text, kind := range textToKeyword {
Expand Down
Loading