Skip to content

Commit 37e09c3

Browse files
jakebaileyJack-Works
authored andcommitted
Disallow line break between entity name and type arguments in typeof expression (microsoft#48755)
1 parent 5ef8a29 commit 37e09c3

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
@@ -3200,7 +3200,8 @@ namespace ts {
32003200
const pos = getNodePos();
32013201
parseExpected(SyntaxKind.TypeOfKeyword);
32023202
const entityName = parseEntityName(/*allowReservedWords*/ true, /*allowPrivateIdentifiers*/ true);
3203-
const typeArguments = tryParseTypeArguments();
3203+
// Make sure we perform ASI to prevent parsing the next line's type arguments as part of an instantiation expression.
3204+
const typeArguments = !scanner.hasPrecedingLineBreak() ? tryParseTypeArguments() : undefined;
32043205
return finishNode(factory.createTypeQueryNode(entityName, typeArguments), pos);
32053206
}
32063207

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)