Skip to content

Emit "Are you missing a semicolon?" for ASI across U+2028/U+2029 - #65439

Closed
Amal Saidov (amalsaidov) wants to merge 1 commit into
microsoft:mainfrom
amalsaidov:fix-asi-nonstandard-newline
Closed

Amal Saidov (amalsaidov) wants to merge 1 commit into
microsoft:mainfrom
amalsaidov:fix-asi-nonstandard-newline

Conversation

@amalsaidov

Copy link
Copy Markdown

Fixes #65433

Problem

When an accidental call is split by a line terminator (the classic ASI footgun), the checker attaches a related Are you missing a semicolon? diagnostic. This was dropped when the newline was a nonstandard line terminator — U+2028 (LINE SEPARATOR) or U+2029 (PARAGRAPH SEPARATOR):

const a = (x: number) => x⁨<U+2028>⁩(1)

Only TS2349: This expression is not callable was reported, without the semicolon hint. This regressed between the previous (UTF-16) compiler and the native port.

Cause

In resolveCallExpression (tsc/internal/checker/checker.go), the preceding line break was detected with rune(text[end-1]) — a single byte. In the native compiler text is a UTF-8 string, so for U+2028/U+2029 this reads only the last continuation byte (0xA8/0xA9), which IsLineBreak does not recognize. In the old compiler, strings were UTF-16 and these separators were a single code unit, so charCodeAt worked.

Fix

Decode the last rune of the skipped text with utf8.DecodeLastRuneInString instead of indexing a byte, so every ECMAScript line terminator (LF, CR, U+2028, U+2029) is recognized. Behavior for single-byte terminators is unchanged.

Tests

  • New case tsc/testdata/tests/cases/compiler/accidentalCallWithLineSeparator.ts covering both U+2028 and U+2029; the baseline now includes the related TS2734: Are you missing a semicolon? sub-error.
  • go -C tsc test -run='TestLocal/accidentalCallWithLineSeparator' ./internal/testrunner passes.
  • Full TestLocal compiler suite (./internal/testrunner) passes with no baseline drift; existing betterErrorForAccidentalCall unaffected.

AI assistance disclosure

This patch was authored with the assistance of an AI coding tool (Claude Code). I have read and understand the change and will shepherd it through review.

🤖 Generated with Claude Code

The accidental-call recovery in resolveCallExpression detected the
preceding line break by reading a single byte (`rune(text[end-1])`).
For the multi-byte line terminators U+2028 (LINE SEPARATOR) and U+2029
(PARAGRAPH SEPARATOR) this reads only the last UTF-8 continuation byte
(0xA8 / 0xA9), which is not a line break, so the "Are you missing a
semicolon?" related diagnostic was dropped. This worked in the previous
(UTF-16) compiler, where those separators are a single code unit.

Decode the last rune of the skipped text instead, so all ECMAScript line
terminators are recognized.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Copilot AI balanced review requested due to automatic review settings November 11, 2026 04:12
@github-project-automation github-project-automation Bot moved this to Not started in PR Backlog Nov 11, 2026
@typescript-automation typescript-automation Bot added the For Backlog Bug PRs that fix a backlog bug label Nov 11, 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 hint is still omitted when U+2028 or U+2029 is followed by indentation because SkipTriviaEx honors StopAfterLineBreak only for CR/LF.

1 open issue
What changed in this PR

Addresses #65433 by restoring the “Are you missing a semicolon?” diagnostic for accidental calls split by U+2028 or U+2029 in the native TypeScript compiler.

Changes:

  • Decodes the final UTF-8 rune instead of inspecting a single byte.
  • Adds regression cases for both Unicode separators and their expected baselines.
File Description
tsc/​internal/​checker/​checker.go Uses UTF-8 decoding to recognize multibyte line terminators.
tsc/​testdata/​tests/​cases/​compiler/​accidentalCallWithLineSeparator.ts Adds accidental-call cases for U+2028 and U+2029.
tsc/​testdata/​baselines/​reference/​compiler/​accidentalCallWithLineSeparator.types Records expected type information.
tsc/​testdata/​baselines/​reference/​compiler/​accidentalCallWithLineSeparator.symbols Records expected symbol information.
tsc/​testdata/​baselines/​reference/​compiler/​accidentalCallWithLineSeparator.js Records expected JavaScript output.
tsc/​testdata/​baselines/​reference/​compiler/​accidentalCallWithLineSeparator.errors.txt Records call errors with related semicolon hints.

Review effort: Balanced

Comment on lines +8781 to +8782
lastChar, _ := utf8.DecodeLastRuneInString(text[:end])
if stringutil.IsLineBreak(lastChar) {
@github-project-automation github-project-automation Bot moved this from Not started to Done in PR Backlog Nov 11, 2026
@amalsaidov

Copy link
Copy Markdown
Author

Thanks for taking a look 🙏

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: Done

Development

Successfully merging this pull request may close these issues.

Incorrect error message when ASI errors involve a nonstandard newline

3 participants