Skip to content

Emit TS2734 for ASI errors involving nonstandard newlines - #65442

Closed
Sai krishna Bodapati (bodapatisaikrishna) wants to merge 1 commit into
microsoft:mainfrom
bodapatisaikrishna:fix/65433-asi-nonstandard-newline
Closed

Sai krishna Bodapati (bodapatisaikrishna) wants to merge 1 commit into
microsoft:mainfrom
bodapatisaikrishna:fix/65433-asi-nonstandard-newline

Conversation

@bodapatisaikrishna

Copy link
Copy Markdown

Fixes #65433

Problem

Accidental call expressions across ECMAScript nonstandard line terminators (U+2028 Line Separator and U+2029 Paragraph Separator), such as const a = (x: number) => x\u2028(1), report TS2349 but fail to emit the related TS2734 ("Are you missing a semicolon?") diagnostic.

Cause

Two factors:

  1. scanner.SkipTriviaEx only handled '\r' and '\n' in its line break cases. 0x2028 and 0x2029 fell into default: which advanced past them without checking options.StopAfterLineBreak.
  2. checker.go checked the character preceding the skipped trivia via raw byte indexing text[pos-1]. For multi-byte UTF-8 runes (0x2028 and 0x2029), text[pos-1] yielded only the trailing byte (0xA8 / 0xA9), which is not recognized as a line break. Additionally, tsbaseline/util.go split lines only on \r?\n, which went out of sync with ComputeECMALineStarts.

Change

  1. Add case 0x2028, 0x2029: to SkipTriviaEx to advance by rune size and stop when options.StopAfterLineBreak is set.
  2. In checker.go, decode the preceding rune with utf8.DecodeLastRuneInString when inspecting trivia boundaries.
  3. Update tsbaseline.lineDelimiter to recognize ECMAScript line terminators \r\n|[\n\r\u2028\u2029].

Testing

  • Added unit tests in scanner_test.go covering SkipTriviaEx line break stops across \r, \n, \r\n, \u2028, \u2029, trailing spaces, and comments.
  • Added compiler regression test betterErrorForAccidentalCallNonstandardLineBreak covering \u2028, \u2029, arrow expressions, declared functions, and trailing whitespace.
  • Ran scanner, checker, and testrunner suites locally.

This patch was written with AI assistance. I have read it, understand it, and will handle review myself.

Copilot AI balanced review requested due to automatic review settings November 11, 2026 15:54
@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 shared regexp removes U+2028/U+2029 characters from existing type-annotation output, causing baseline comparisons to fail against unchanged references.

1 open issue
What changed in this PR

Fixes #65433 by restoring the TS2734 “Are you missing a semicolon?” hint for accidental calls across U+2028 and U+2029 line separators.

Changes:

  • Recognizes Unicode line separators when skipping trivia and checking call boundaries.
  • Aligns diagnostic baseline line splitting with ECMAScript line terminators.
  • Adds scanner tests and compiler regression coverage with expected baselines.
File Description
tsc/​testdata/​tests/​cases/​compiler/​betterErrorForAccidentalCallNonstandardLineBreak.ts Adds Unicode newline regression cases.
tsc/​testdata/​baselines/​reference/​compiler/​betterErrorForAccidentalCallNonstandardLineBreak.types Records expected type annotations.
tsc/​testdata/​baselines/​reference/​compiler/​betterErrorForAccidentalCallNonstandardLineBreak.symbols Records expected symbol annotations.
tsc/​testdata/​baselines/​reference/​compiler/​betterErrorForAccidentalCallNonstandardLineBreak.js Records expected JavaScript output.
tsc/​testdata/​baselines/​reference/​compiler/​betterErrorForAccidentalCallNonstandardLineBreak.errors.txt Records TS2349 errors with TS2734 hints.
tsc/​internal/​testutil/​tsbaseline/​util.go Expands baseline line-delimiter recognition.
tsc/​internal/​scanner/​scanner.go Stops trivia scanning at Unicode line separators.
tsc/​internal/​scanner/​scanner_test.go Tests line-break stopping behavior.
tsc/​internal/​checker/​checker.go Decodes the preceding UTF-8 rune when detecting newlines.

Review effort: Balanced


var (
lineDelimiter = regexp.MustCompile("\r?\n")
lineDelimiter = regexp.MustCompile("\r\n|[\n\r\u2028\u2029]")
@github-project-automation github-project-automation Bot moved this from Not started to Done in PR Backlog Nov 11, 2026
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