Skip to content

Commit 0403aeb

Browse files
smg99cursoragent
andcommitted
fix(65433): restore ASI semicolon hint for U+2028/U+2029
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>
1 parent 6327ae1 commit 0403aeb

8 files changed

Lines changed: 129 additions & 2 deletions

‎tsc/internal/checker/checker.go‎

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import (
1212
"strings"
1313
"sync"
1414
"sync/atomic"
15+
"unicode/utf8"
1516

1617
"github.com/microsoft/TypeScript/tsc/internal/ast"
1718
"github.com/microsoft/TypeScript/tsc/internal/binder"
@@ -8790,8 +8791,14 @@ func (c *Checker) resolveCallExpression(node *ast.Node, candidatesOutArray *[]*S
87908791
if len(node.Arguments()) == 1 {
87918792
text := ast.GetSourceFileOfNode(node).Text()
87928793
options := scanner.SkipTriviaOptions{StopAfterLineBreak: true}
8793-
if stringutil.IsLineBreak(rune(text[scanner.SkipTriviaEx(text, node.Expression().End(), &options)-1])) {
8794-
relatedInformation = createDiagnosticForNode(node.Expression(), diagnostics.Are_you_missing_a_semicolon)
8794+
afterTrivia := scanner.SkipTriviaEx(text, node.Expression().End(), &options)
8795+
// Decode the previous UTF-8 rune; indexing text[afterTrivia-1] only works
8796+
// for ASCII line breaks (LF/CR), not U+2028 / U+2029 (issue #65433).
8797+
if afterTrivia > 0 {
8798+
prev, _ := utf8.DecodeLastRuneInString(text[:afterTrivia])
8799+
if stringutil.IsLineBreak(prev) {
8800+
relatedInformation = createDiagnosticForNode(node.Expression(), diagnostics.Are_you_missing_a_semicolon)
8801+
}
87958802
}
87968803
}
87978804
c.invocationError(node.Expression(), apparentType, SignatureKindCall, relatedInformation)

‎tsc/internal/scanner/scanner.go‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2443,6 +2443,12 @@ func SkipTriviaEx(text string, pos int, options *SkipTriviaOptions) int {
24432443
default:
24442444
if ch > rune(maxAsciiCharacter) && stringutil.IsWhiteSpaceLike(ch) {
24452445
pos += size
2446+
// U+2028 / U+2029 are line terminators (ECMAScript 7.3). When asked to
2447+
// stop after a line break, treat them like LF/CR rather than continuing
2448+
// past them as ordinary whitespace (issue #65433).
2449+
if options.StopAfterLineBreak && stringutil.IsLineBreak(ch) {
2450+
return pos
2451+
}
24462452
continue
24472453
}
24482454
}

‎tsc/internal/scanner/scanner_test.go‎

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -212,3 +212,30 @@ func TestRegExpLiteralReplacementCharacterInClassRange(t *testing.T) {
212212
})
213213
}
214214
}
215+
216+
func TestSkipTriviaStopsAfterUnicodeLineBreaks(t *testing.T) {
217+
t.Parallel()
218+
219+
options := &SkipTriviaOptions{StopAfterLineBreak: true}
220+
tests := []struct {
221+
name string
222+
text string
223+
}{
224+
{name: "LF", text: "x\n("},
225+
{name: "CR", text: "x\r("},
226+
{name: "CRLF", text: "x\r\n("},
227+
{name: "line separator", text: "x\u2028("},
228+
{name: "paragraph separator", text: "x\u2029("},
229+
}
230+
231+
for _, test := range tests {
232+
t.Run(test.name, func(t *testing.T) {
233+
t.Parallel()
234+
after := SkipTriviaEx(test.text, 1, options)
235+
assert.Assert(t, after > 1)
236+
prev, _ := utf8.DecodeLastRuneInString(test.text[:after])
237+
assert.Assert(t, stringutil.IsLineBreak(prev), "expected previous rune to be a line break, got %U", prev)
238+
assert.Equal(t, after, len(test.text)-1) // stopped before '('
239+
})
240+
}
241+
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
betterErrorForAccidentalCallLineSeparator.ts(3,26): error TS2349: This expression is not callable.
2+
Type 'Number' has no call signatures.
3+
betterErrorForAccidentalCallLineSeparator.ts(6,1): error TS2349: This expression is not callable.
4+
Type 'String' has no call signatures.
5+
6+
7+
==== betterErrorForAccidentalCallLineSeparator.ts (2 errors) ====
8+
declare function foo(): string;
9+
10+
const a = (x: number) => x
(1);
11+
~
12+
!!! error TS2349: This expression is not callable.
13+
!!! error TS2349: Type 'Number' has no call signatures.
14+
!!! related TS2734 betterErrorForAccidentalCallLineSeparator.ts:3:26: Are you missing a semicolon?
15+
16+
foo()
(1 as number).toString();
17+
18+
19+
!!! error TS2349: This expression is not callable.
20+
!!! error TS2349: Type 'String' has no call signatures.
21+
!!! related TS2734 betterErrorForAccidentalCallLineSeparator.ts:6:1: Are you missing a semicolon?
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
//// [tests/cases/compiler/betterErrorForAccidentalCallLineSeparator.ts] ////
2+
3+
//// [betterErrorForAccidentalCallLineSeparator.ts]
4+
declare function foo(): string;
5+
6+
const a = (x: number) => x
(1);
7+
8+
foo()
(1 as number).toString();
9+
10+
11+
//// [betterErrorForAccidentalCallLineSeparator.js]
12+
"use strict";
13+
const a = (x) => x(1);
14+
foo()(1).toString();
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
//// [tests/cases/compiler/betterErrorForAccidentalCallLineSeparator.ts] ////
2+
3+
=== betterErrorForAccidentalCallLineSeparator.ts ===
4+
declare function foo(): string;
5+
>foo : Symbol(foo, Decl(betterErrorForAccidentalCallLineSeparator.ts, 0, 0))
6+
7+
const a = (x: number) => x
8+
>a : Symbol(a, Decl(betterErrorForAccidentalCallLineSeparator.ts, 2, 5))
9+
>x : Symbol(x, Decl(betterErrorForAccidentalCallLineSeparator.ts, 2, 11))
10+
>x : Symbol(x, Decl(betterErrorForAccidentalCallLineSeparator.ts, 2, 11))
11+
12+
(1);
13+
14+
foo()
15+
>foo : Symbol(foo, Decl(betterErrorForAccidentalCallLineSeparator.ts, 0, 0))
16+
17+
(1 as number).toString();
18+
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
//// [tests/cases/compiler/betterErrorForAccidentalCallLineSeparator.ts] ////
2+
3+
=== betterErrorForAccidentalCallLineSeparator.ts ===
4+
declare function foo(): string;
5+
>foo : () => string
6+
7+
const a = (x: number) => x
8+
>a : (x: number) => any
9+
>(x: number) => x
(1) : (x: number) => any
10+
>x : number
11+
>x
(1) : any
12+
>x : number
13+
14+
(1);
15+
>1 : 1
16+
17+
foo()
18+
>foo()
(1 as number).toString() : any
19+
>foo()
(1 as number).toString : any
20+
>foo()
(1 as number) : any
21+
>foo() : string
22+
>foo : () => string
23+
24+
(1 as number).toString();
25+
>1 as number : number
26+
>1 : 1
27+
>toString : any
28+
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
// @target: es2015
2+
declare function foo(): string;
3+
4+
const a = (x: number) => x
(1);
5+
6+
foo()
(1 as number).toString();

0 commit comments

Comments
 (0)