mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-02-06 02:33:53 -06:00
Disallow line break between entity name and type arguments in typeof expression (#48755)
This commit is contained in:
parent
65f6cb23d3
commit
d3943fc86f
@ -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);
|
||||
}
|
||||
|
||||
|
||||
@ -0,0 +1,9 @@
|
||||
//// [newLineInTypeofInstantiation.ts]
|
||||
interface Example {
|
||||
(a: number): typeof a
|
||||
|
||||
<T>(): void
|
||||
}
|
||||
|
||||
|
||||
//// [newLineInTypeofInstantiation.js]
|
||||
@ -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))
|
||||
}
|
||||
|
||||
@ -0,0 +1,9 @@
|
||||
=== tests/cases/compiler/newLineInTypeofInstantiation.ts ===
|
||||
interface Example {
|
||||
(a: number): typeof a
|
||||
>a : number
|
||||
>a : number
|
||||
|
||||
<T>(): void
|
||||
}
|
||||
|
||||
5
tests/cases/compiler/newLineInTypeofInstantiation.ts
Normal file
5
tests/cases/compiler/newLineInTypeofInstantiation.ts
Normal file
@ -0,0 +1,5 @@
|
||||
interface Example {
|
||||
(a: number): typeof a
|
||||
|
||||
<T>(): void
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user