Disallow line break between entity name and type arguments in typeof expression (#48755)

This commit is contained in:
Jake Bailey 2022-04-18 16:18:31 -07:00 committed by GitHub
parent 65f6cb23d3
commit d3943fc86f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 37 additions and 1 deletions

View File

@ -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);
}

View File

@ -0,0 +1,9 @@
//// [newLineInTypeofInstantiation.ts]
interface Example {
(a: number): typeof a
<T>(): void
}
//// [newLineInTypeofInstantiation.js]

View File

@ -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))
<T>(): void
>T : Symbol(T, Decl(newLineInTypeofInstantiation.ts, 3, 5))
}

View File

@ -0,0 +1,9 @@
=== tests/cases/compiler/newLineInTypeofInstantiation.ts ===
interface Example {
(a: number): typeof a
>a : number
>a : number
<T>(): void
}

View File

@ -0,0 +1,5 @@
interface Example {
(a: number): typeof a
<T>(): void
}