Skip to content

Commit d3943fc

Browse files
authored
Disallow line break between entity name and type arguments in typeof expression (microsoft#48755)
1 parent 65f6cb2 commit d3943fc

File tree

5 files changed

+37
-1
lines changed

5 files changed

+37
-1
lines changed

src/compiler/parser.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3189,7 +3189,8 @@ namespace ts {
31893189
const pos = getNodePos();
31903190
parseExpected(SyntaxKind.TypeOfKeyword);
31913191
const entityName = parseEntityName(/*allowReservedWords*/ true, /*allowPrivateIdentifiers*/ true);
3192-
const typeArguments = tryParseTypeArguments();
3192+
// Make sure we perform ASI to prevent parsing the next line's type arguments as part of an instantiation expression.
3193+
const typeArguments = !scanner.hasPrecedingLineBreak() ? tryParseTypeArguments() : undefined;
31933194
return finishNode(factory.createTypeQueryNode(entityName, typeArguments), pos);
31943195
}
31953196

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
//// [newLineInTypeofInstantiation.ts]
2+
interface Example {
3+
(a: number): typeof a
4+
5+
<T>(): void
6+
}
7+
8+
9+
//// [newLineInTypeofInstantiation.js]
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
=== tests/cases/compiler/newLineInTypeofInstantiation.ts ===
2+
interface Example {
3+
>Example : Symbol(Example, Decl(newLineInTypeofInstantiation.ts, 0, 0))
4+
5+
(a: number): typeof a
6+
>a : Symbol(a, Decl(newLineInTypeofInstantiation.ts, 1, 5))
7+
>a : Symbol(a, Decl(newLineInTypeofInstantiation.ts, 1, 5))
8+
9+
<T>(): void
10+
>T : Symbol(T, Decl(newLineInTypeofInstantiation.ts, 3, 5))
11+
}
12+
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
=== tests/cases/compiler/newLineInTypeofInstantiation.ts ===
2+
interface Example {
3+
(a: number): typeof a
4+
>a : number
5+
>a : number
6+
7+
<T>(): void
8+
}
9+
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
interface Example {
2+
(a: number): typeof a
3+
4+
<T>(): void
5+
}

0 commit comments

Comments
 (0)