Skip to content
Closed
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
9 changes: 7 additions & 2 deletions tsc/internal/checker/checker.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (
"strings"
"sync"
"sync/atomic"
"unicode/utf8"

"github.com/microsoft/TypeScript/tsc/internal/ast"
"github.com/microsoft/TypeScript/tsc/internal/binder"
Expand Down Expand Up @@ -8785,8 +8786,12 @@ func (c *Checker) resolveCallExpression(node *ast.Node, candidatesOutArray *[]*S
if len(node.Arguments()) == 1 {
text := ast.GetSourceFileOfNode(node).Text()
options := scanner.SkipTriviaOptions{StopAfterLineBreak: true}
if stringutil.IsLineBreak(rune(text[scanner.SkipTriviaEx(text, node.Expression().End(), &options)-1])) {
relatedInformation = createDiagnosticForNode(node.Expression(), diagnostics.Are_you_missing_a_semicolon)
end := scanner.SkipTriviaEx(text, node.Expression().End(), &options)
if end > 0 {
lastRune, _ := utf8.DecodeLastRuneInString(text[:end])
if stringutil.IsLineBreak(lastRune) {
relatedInformation = createDiagnosticForNode(node.Expression(), diagnostics.Are_you_missing_a_semicolon)
}
}
}
c.invocationError(node.Expression(), apparentType, SignatureKindCall, relatedInformation)
Expand Down
7 changes: 7 additions & 0 deletions tsc/internal/scanner/scanner.go
Original file line number Diff line number Diff line change
Expand Up @@ -2376,6 +2376,13 @@ func SkipTriviaEx(text string, pos int, options *SkipTriviaOptions) int {
}
ch, size := utf8.DecodeRuneInString(text[pos:])
switch ch {
case '\u2028', '\u2029':
pos += size
if options.StopAfterLineBreak {
return pos
}
canConsumeStar = options.InJSDoc
continue
case '\r':
if pos+1 < textLen && text[pos+1] == '\n' {
pos++
Expand Down
14 changes: 14 additions & 0 deletions tsc/internal/scanner/scanner_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,20 @@ func TestNormalizeJSDocTypeSourceText(t *testing.T) {
}
}

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

for _, lineBreak := range []string{"\u2028", "\u2029"} {
t.Run(lineBreak, func(t *testing.T) {
t.Parallel()
text := "x" + lineBreak + " (1)"
options := SkipTriviaOptions{StopAfterLineBreak: true}

assert.Equal(t, SkipTriviaEx(text, 1, &options), 1+len(lineBreak))
})
}
}

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

Expand Down
2 changes: 1 addition & 1 deletion tsc/internal/testutil/tsbaseline/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (
)

var (
lineDelimiter = regexp.MustCompile("\r?\n")
lineDelimiter = regexp.MustCompile("\r?\n|\u2028|\u2029")
nonWhitespace = regexp.MustCompile(`\S`)
tsExtension = regexp.MustCompile(`\.tsx?$`)
testPathCharacters = regexp.MustCompile(`[\^<>:"|?*%]`)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
issue65433NonstandardNewlineASI.ts(1,26): error TS2349: This expression is not callable.
Type 'Number' has no call signatures.
issue65433NonstandardNewlineASI.ts(3,26): error TS2349: This expression is not callable.
Type 'Number' has no call signatures.
issue65433NonstandardNewlineASI.ts(5,26): error TS2349: This expression is not callable.
Type 'Number' has no call signatures.


==== issue65433NonstandardNewlineASI.ts (3 errors) ====
const a = (x: number) => x
~
!!! error TS2349: This expression is not callable.
!!! error TS2349: Type 'Number' has no call signatures.
!!! related TS2734 issue65433NonstandardNewlineASI.ts:1:26: Are you missing a semicolon?
(1)
const b = (x: number) => x
~
!!! error TS2349: This expression is not callable.
!!! error TS2349: Type 'Number' has no call signatures.
!!! related TS2734 issue65433NonstandardNewlineASI.ts:3:26: Are you missing a semicolon?
(1)
const c = (x: number) => x
~
!!! error TS2349: This expression is not callable.
!!! error TS2349: Type 'Number' has no call signatures.
!!! related TS2734 issue65433NonstandardNewlineASI.ts:5:26: Are you missing a semicolon?
(1)

Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
//// [tests/cases/compiler/issue65433NonstandardNewlineASI.ts] ////

//// [issue65433NonstandardNewlineASI.ts]
const a = (x: number) => x
(1)
const b = (x: number) => x
 (1)
const c = (x: number) => x
 (1)


//// [issue65433NonstandardNewlineASI.js]
"use strict";
const a = (x) => x(1);
const b = (x) => x(1);
const c = (x) => x(1);
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
//// [tests/cases/compiler/issue65433NonstandardNewlineASI.ts] ////

=== issue65433NonstandardNewlineASI.ts ===
const a = (x: number) => x
>a : Symbol(a, Decl(issue65433NonstandardNewlineASI.ts, 0, 5))
>x : Symbol(x, Decl(issue65433NonstandardNewlineASI.ts, 0, 11))
>x : Symbol(x, Decl(issue65433NonstandardNewlineASI.ts, 0, 11))

(1)
const b = (x: number) => x
>b : Symbol(b, Decl(issue65433NonstandardNewlineASI.ts, 2, 5))
>x : Symbol(x, Decl(issue65433NonstandardNewlineASI.ts, 2, 11))
>x : Symbol(x, Decl(issue65433NonstandardNewlineASI.ts, 2, 11))

(1)
const c = (x: number) => x
>c : Symbol(c, Decl(issue65433NonstandardNewlineASI.ts, 4, 5))
>x : Symbol(x, Decl(issue65433NonstandardNewlineASI.ts, 4, 11))
>x : Symbol(x, Decl(issue65433NonstandardNewlineASI.ts, 4, 11))

(1)

Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
//// [tests/cases/compiler/issue65433NonstandardNewlineASI.ts] ////

=== issue65433NonstandardNewlineASI.ts ===
const a = (x: number) => x
>a : (x: number) => any
>(x: number) => x(1) : (x: number) => any
>x : number
>x(1) : any
>x : number

(1)
>1 : 1

const b = (x: number) => x
>b : (x: number) => any
>(x: number) => x (1) : (x: number) => any
>x : number
>x (1) : any
>x : number

(1)
>1 : 1

const c = (x: number) => x
>c : (x: number) => any
>(x: number) => x (1) : (x: number) => any
>x : number
>x (1) : any
>x : number

(1)
>1 : 1

Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
const a = (x: number) => x
(1)
const b = (x: number) => x
 (1)
const c = (x: number) => x
 (1)