From fd4a57dd93f330b077cb225629e16399b7b98389 Mon Sep 17 00:00:00 2001 From: Jake Bailey <5341706+jakebailey@users.noreply.github.com> Date: Mon, 18 Apr 2022 15:26:35 -0700 Subject: [PATCH 1/2] Add test --- .../newLineInTypeofInstantiation.errors.txt | 15 +++++++++++++++ .../reference/newLineInTypeofInstantiation.js | 9 +++++++++ .../newLineInTypeofInstantiation.symbols | 12 ++++++++++++ .../reference/newLineInTypeofInstantiation.types | 9 +++++++++ .../compiler/newLineInTypeofInstantiation.ts | 5 +++++ 5 files changed, 50 insertions(+) create mode 100644 tests/baselines/reference/newLineInTypeofInstantiation.errors.txt create mode 100644 tests/baselines/reference/newLineInTypeofInstantiation.js create mode 100644 tests/baselines/reference/newLineInTypeofInstantiation.symbols create mode 100644 tests/baselines/reference/newLineInTypeofInstantiation.types create mode 100644 tests/cases/compiler/newLineInTypeofInstantiation.ts diff --git a/tests/baselines/reference/newLineInTypeofInstantiation.errors.txt b/tests/baselines/reference/newLineInTypeofInstantiation.errors.txt new file mode 100644 index 0000000000000..a03a9ef4afe05 --- /dev/null +++ b/tests/baselines/reference/newLineInTypeofInstantiation.errors.txt @@ -0,0 +1,15 @@ +tests/cases/compiler/newLineInTypeofInstantiation.ts(4,6): error TS2635: Type 'number' has no signatures for which the type argument list is applicable. +tests/cases/compiler/newLineInTypeofInstantiation.ts(4,8): error TS1005: ';' expected. + + +==== tests/cases/compiler/newLineInTypeofInstantiation.ts (2 errors) ==== + interface Example { + (a: number): typeof a + + (): void + ~ +!!! error TS2635: Type 'number' has no signatures for which the type argument list is applicable. + ~ +!!! error TS1005: ';' expected. + } + \ No newline at end of file diff --git a/tests/baselines/reference/newLineInTypeofInstantiation.js b/tests/baselines/reference/newLineInTypeofInstantiation.js new file mode 100644 index 0000000000000..b43b677030531 --- /dev/null +++ b/tests/baselines/reference/newLineInTypeofInstantiation.js @@ -0,0 +1,9 @@ +//// [newLineInTypeofInstantiation.ts] +interface Example { + (a: number): typeof a + + (): void +} + + +//// [newLineInTypeofInstantiation.js] diff --git a/tests/baselines/reference/newLineInTypeofInstantiation.symbols b/tests/baselines/reference/newLineInTypeofInstantiation.symbols new file mode 100644 index 0000000000000..e58dad7e22242 --- /dev/null +++ b/tests/baselines/reference/newLineInTypeofInstantiation.symbols @@ -0,0 +1,12 @@ +=== tests/cases/compiler/newLineInTypeofInstantiation.ts === +interface Example { +>Example : Symbol(Example, Decl(newLineInTypeofInstantiation.ts, 0, 0)) + + (a: number): typeof a +>a : Symbol(a, Decl(newLineInTypeofInstantiation.ts, 1, 5)) +>a : Symbol(a, Decl(newLineInTypeofInstantiation.ts, 1, 5)) + + (): void +>T : Symbol(T) +} + diff --git a/tests/baselines/reference/newLineInTypeofInstantiation.types b/tests/baselines/reference/newLineInTypeofInstantiation.types new file mode 100644 index 0000000000000..a57d7df124b95 --- /dev/null +++ b/tests/baselines/reference/newLineInTypeofInstantiation.types @@ -0,0 +1,9 @@ +=== tests/cases/compiler/newLineInTypeofInstantiation.ts === +interface Example { + (a: number): typeof a +>a : number +>a : number + + (): void +} + diff --git a/tests/cases/compiler/newLineInTypeofInstantiation.ts b/tests/cases/compiler/newLineInTypeofInstantiation.ts new file mode 100644 index 0000000000000..99259acec79f4 --- /dev/null +++ b/tests/cases/compiler/newLineInTypeofInstantiation.ts @@ -0,0 +1,5 @@ +interface Example { + (a: number): typeof a + + (): void +} From a5a7b7e611bfb1b4b9ae3d6d8ef62147b761dd9b Mon Sep 17 00:00:00 2001 From: Jake Bailey <5341706+jakebailey@users.noreply.github.com> Date: Mon, 18 Apr 2022 15:53:51 -0700 Subject: [PATCH 2/2] Disallow line break between entity name and type arguments in typeof expression --- src/compiler/parser.ts | 3 ++- .../newLineInTypeofInstantiation.errors.txt | 15 --------------- .../newLineInTypeofInstantiation.symbols | 2 +- 3 files changed, 3 insertions(+), 17 deletions(-) delete mode 100644 tests/baselines/reference/newLineInTypeofInstantiation.errors.txt diff --git a/src/compiler/parser.ts b/src/compiler/parser.ts index 247381f02516b..e57a3fa98f390 100644 --- a/src/compiler/parser.ts +++ b/src/compiler/parser.ts @@ -3189,7 +3189,8 @@ namespace ts { const pos = getNodePos(); parseExpected(SyntaxKind.TypeOfKeyword); const entityName = parseEntityName(/*allowReservedWords*/ true, /*allowPrivateIdentifiers*/ true); - const typeArguments = tryParseTypeArguments(); + // Make sure we perform ASI to prevent parsing the next line's type arguments as part of an instantiation expression. + const typeArguments = !scanner.hasPrecedingLineBreak() ? tryParseTypeArguments() : undefined; return finishNode(factory.createTypeQueryNode(entityName, typeArguments), pos); } diff --git a/tests/baselines/reference/newLineInTypeofInstantiation.errors.txt b/tests/baselines/reference/newLineInTypeofInstantiation.errors.txt deleted file mode 100644 index a03a9ef4afe05..0000000000000 --- a/tests/baselines/reference/newLineInTypeofInstantiation.errors.txt +++ /dev/null @@ -1,15 +0,0 @@ -tests/cases/compiler/newLineInTypeofInstantiation.ts(4,6): error TS2635: Type 'number' has no signatures for which the type argument list is applicable. -tests/cases/compiler/newLineInTypeofInstantiation.ts(4,8): error TS1005: ';' expected. - - -==== tests/cases/compiler/newLineInTypeofInstantiation.ts (2 errors) ==== - interface Example { - (a: number): typeof a - - (): void - ~ -!!! error TS2635: Type 'number' has no signatures for which the type argument list is applicable. - ~ -!!! error TS1005: ';' expected. - } - \ No newline at end of file diff --git a/tests/baselines/reference/newLineInTypeofInstantiation.symbols b/tests/baselines/reference/newLineInTypeofInstantiation.symbols index e58dad7e22242..2a3ccf8097e86 100644 --- a/tests/baselines/reference/newLineInTypeofInstantiation.symbols +++ b/tests/baselines/reference/newLineInTypeofInstantiation.symbols @@ -7,6 +7,6 @@ interface Example { >a : Symbol(a, Decl(newLineInTypeofInstantiation.ts, 1, 5)) (): void ->T : Symbol(T) +>T : Symbol(T, Decl(newLineInTypeofInstantiation.ts, 3, 5)) }