Skip to content

fix(65433): restore ASI semicolon hint for U+2028/U+2029 - #65715

Open
Sumit G (smg99) wants to merge 1 commit into
microsoft:mainfrom
smg99:fix/65433-asi-line-separator
Open

Sumit G (smg99) wants to merge 1 commit into
microsoft:mainfrom
smg99:fix/65433-asi-line-separator

Conversation

@smg99

Copy link
Copy Markdown
Contributor

Fixes #65433

AI assistance

This change was authored with AI coding-tool assistance. I reviewed the resulting patch, understand the root cause and fix, and will handle review feedback myself.

Problem

When a non-callable expression is followed by (args) across an ECMAScript line terminator, TypeScript adds related diagnostic TS2734 ("Are you missing a semicolon?"). That hint worked for LF/CR but not for U+2028 (line separator) / U+2029 (paragraph separator), e.g.:

const a = (x: number) => x\u2028(1)

Cause

Two Go-port issues:

  1. SkipTriviaEx with StopAfterLineBreak only stopped for \n/\r. U+2028/U+2029 were treated as generic Unicode whitespace and skipped past.
  2. The checker tested rune(text[pos-1]) after trivia. That is a UTF-8 byte index, so for the 3-byte encodings of LS/PS it never saw a line break.

Fix

  • Stop after U+2028/U+2029 in SkipTriviaEx when StopAfterLineBreak is set.
  • Use utf8.DecodeLastRuneInString when checking the character before the call args.

Tests

  • Compiler case betterErrorForAccidentalCallLineSeparator.ts (issue repro with U+2028) + baselines showing related TS2734.
  • Unit test TestSkipTriviaStopsAfterUnicodeLineBreaks covers LF, CR, CRLF, U+2028, and U+2029.

Notes

  • A U+2029 compiler baseline was not added: the error-baseline harness panics when formatting that case (slice bounds out of range). Scanner unit coverage still includes U+2029.
  • Pre-existing: ls/change/delete.go and ls/change/trackerimpl.go still use text[pos-1] after SkipTriviaEx(..., StopAfterLineBreak). With this scanner fix those paths can now run for LS/PS, but the byte index remains incorrect for multi-byte terminators. Impact is limited to language-service edits on rare LS/PS source; suitable follow-up, not required for the diagnostic fix.

Checklist

  • Associated issue is in the Backlog milestone
  • Branch is up to date with main
  • Focused Go/compiler tests validating the change
  • Full npx hereby test / lint / format not run in this environment (Go-focused verification only)

Made with Cursor

Stop SkipTrivia after Unicode line terminators when requested, and
decode the previous UTF-8 rune when checking for a line break so the
"Are you missing a semicolon?" related diagnostic fires for LS/PS ASI.

Co-authored-by: Cursor <cursoragent@cursor.com>
Copilot AI balanced review requested due to automatic review settings November 28, 2026 05:19
@github-project-automation github-project-automation Bot moved this to Not started in PR Backlog Nov 28, 2026
@typescript-automation typescript-automation Bot added the For Backlog Bug PRs that fix a backlog bug label Nov 28, 2026

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

The regression tests also pass with the original scanner, so they need whitespace after U+2028/U+2029 and position assertions immediately after each terminator to catch a reverted scanner fix.

1 open issue
What changed in this PR

Restores the “Are you missing a semicolon?” diagnostic hint for accidental calls separated by U+2028 or U+2029, addressing the Go-port regression in #65433.

Changes:

  • Makes trivia scanning stop after Unicode line terminators when requested.
  • Decodes the preceding UTF-8 rune when deciding whether to attach the hint.
  • Adds scanner tests and a U+2028 compiler regression case with diagnostic, emit, type, and symbol baselines.
File Description
tsc/​testdata/​tests/​cases/​compiler/​betterErrorForAccidentalCallLineSeparator.ts Adds U+2028 accidental-call cases.
tsc/​testdata/​baselines/​reference/​compiler/​betterErrorForAccidentalCallLineSeparator.types Records inferred types.
tsc/​testdata/​baselines/​reference/​compiler/​betterErrorForAccidentalCallLineSeparator.symbols Records symbol bindings.
tsc/​testdata/​baselines/​reference/​compiler/​betterErrorForAccidentalCallLineSeparator.js Records emitted JavaScript.
tsc/​testdata/​baselines/​reference/​compiler/​betterErrorForAccidentalCallLineSeparator.errors.txt Records invocation errors and TS2734 hints.
tsc/​internal/​scanner/​scanner.go Stops trivia scanning after Unicode line terminators.
tsc/​internal/​scanner/​scanner_test.go Tests scanner offsets across five newline forms.
tsc/​internal/​checker/​checker.go Uses UTF-8 decoding for the semicolon-hint check.

Review effort: Balanced

Comment on lines +224 to +238
{name: "LF", text: "x\n("},
{name: "CR", text: "x\r("},
{name: "CRLF", text: "x\r\n("},
{name: "line separator", text: "x\u2028("},
{name: "paragraph separator", text: "x\u2029("},
}

for _, test := range tests {
t.Run(test.name, func(t *testing.T) {
t.Parallel()
after := SkipTriviaEx(test.text, 1, options)
assert.Assert(t, after > 1)
prev, _ := utf8.DecodeLastRuneInString(test.text[:after])
assert.Assert(t, stringutil.IsLineBreak(prev), "expected previous rune to be a line break, got %U", prev)
assert.Equal(t, after, len(test.text)-1) // stopped before '('

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

For Backlog Bug PRs that fix a backlog bug

Projects

Status: Not started

Development

Successfully merging this pull request may close these issues.

Incorrect error message when ASI errors involve a nonstandard newline

2 participants