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
7 changes: 6 additions & 1 deletion 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 @@ -8774,7 +8775,11 @@ 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])) {
end := scanner.SkipTriviaEx(text, node.Expression().End(), &options)
// Decode the last rune rather than indexing a single byte, so that
// multi-byte line terminators (U+2028, U+2029) are recognized.
lastChar, _ := utf8.DecodeLastRuneInString(text[:end])
if stringutil.IsLineBreak(lastChar) {
Comment on lines +8781 to +8782
relatedInformation = createDiagnosticForNode(node.Expression(), diagnostics.Are_you_missing_a_semicolon)
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
accidentalCallWithLineSeparator.ts(3,1): error TS2349: This expression is not callable.
Type 'String' has no call signatures.
accidentalCallWithLineSeparator.ts(6,1): error TS2349: This expression is not callable.
Type 'String' has no call signatures.


==== accidentalCallWithLineSeparator.ts (2 errors) ====
declare function foo(): string;

foo()
(1 as number).toString();
~~~~~
!!! error TS2349: This expression is not callable.
!!! error TS2349: Type 'String' has no call signatures.
!!! related TS2734 accidentalCallWithLineSeparator.ts:3:1: Are you missing a semicolon?

foo()
(1 as number).toString();


!!! error TS2349: This expression is not callable.
!!! error TS2349: Type 'String' has no call signatures.
!!! related TS2734 accidentalCallWithLineSeparator.ts:6:1: Are you missing a semicolon?
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
//// [tests/cases/compiler/accidentalCallWithLineSeparator.ts] ////

//// [accidentalCallWithLineSeparator.ts]
declare function foo(): string;

foo()
(1 as number).toString();

foo()
(1 as number).toString();


//// [accidentalCallWithLineSeparator.js]
"use strict";
foo()(1).toString();
foo()(1).toString();
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
//// [tests/cases/compiler/accidentalCallWithLineSeparator.ts] ////

=== accidentalCallWithLineSeparator.ts ===
declare function foo(): string;
>foo : Symbol(foo, Decl(accidentalCallWithLineSeparator.ts, 0, 0))

foo()
>foo : Symbol(foo, Decl(accidentalCallWithLineSeparator.ts, 0, 0))

(1 as number).toString();

foo()
>foo : Symbol(foo, Decl(accidentalCallWithLineSeparator.ts, 0, 0))

(1 as number).toString();

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

=== accidentalCallWithLineSeparator.ts ===
declare function foo(): string;
>foo : () => string

foo()
>foo()
(1 as number).toString() : any
>foo()
(1 as number).toString : any
>foo()
(1 as number) : any
>foo() : string
>foo : () => string

(1 as number).toString();
>1 as number : number
>1 : 1
>toString : any

foo()
>foo()
(1 as number).toString() : any
>foo()
(1 as number).toString : any
>foo()
(1 as number) : any
>foo() : string
>foo : () => string

(1 as number).toString();
>1 as number : number
>1 : 1
>toString : any

Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
// @target: es2015
declare function foo(): string;

foo()
(1 as number).toString();

foo()
(1 as number).toString();