diff --git a/tsc/internal/checker/checker.go b/tsc/internal/checker/checker.go index 950b9a8e30fb8..d70db0eb6e96d 100644 --- a/tsc/internal/checker/checker.go +++ b/tsc/internal/checker/checker.go @@ -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" @@ -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) { relatedInformation = createDiagnosticForNode(node.Expression(), diagnostics.Are_you_missing_a_semicolon) } } diff --git a/tsc/testdata/baselines/reference/compiler/accidentalCallWithLineSeparator.errors.txt b/tsc/testdata/baselines/reference/compiler/accidentalCallWithLineSeparator.errors.txt new file mode 100644 index 0000000000000..fa845e6e7dbc3 --- /dev/null +++ b/tsc/testdata/baselines/reference/compiler/accidentalCallWithLineSeparator.errors.txt @@ -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? \ No newline at end of file diff --git a/tsc/testdata/baselines/reference/compiler/accidentalCallWithLineSeparator.js b/tsc/testdata/baselines/reference/compiler/accidentalCallWithLineSeparator.js new file mode 100644 index 0000000000000..4b41efbd03922 --- /dev/null +++ b/tsc/testdata/baselines/reference/compiler/accidentalCallWithLineSeparator.js @@ -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(); diff --git a/tsc/testdata/baselines/reference/compiler/accidentalCallWithLineSeparator.symbols b/tsc/testdata/baselines/reference/compiler/accidentalCallWithLineSeparator.symbols new file mode 100644 index 0000000000000..b413ca2e74fe6 --- /dev/null +++ b/tsc/testdata/baselines/reference/compiler/accidentalCallWithLineSeparator.symbols @@ -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(); + diff --git a/tsc/testdata/baselines/reference/compiler/accidentalCallWithLineSeparator.types b/tsc/testdata/baselines/reference/compiler/accidentalCallWithLineSeparator.types new file mode 100644 index 0000000000000..0031d07304a9b --- /dev/null +++ b/tsc/testdata/baselines/reference/compiler/accidentalCallWithLineSeparator.types @@ -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 + diff --git a/tsc/testdata/tests/cases/compiler/accidentalCallWithLineSeparator.ts b/tsc/testdata/tests/cases/compiler/accidentalCallWithLineSeparator.ts new file mode 100644 index 0000000000000..ba6a566a4aca0 --- /dev/null +++ b/tsc/testdata/tests/cases/compiler/accidentalCallWithLineSeparator.ts @@ -0,0 +1,6 @@ +// @target: es2015 +declare function foo(): string; + +foo()
(1 as number).toString(); + +foo()
(1 as number).toString();