Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 2 commits into from
Apr 18, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/compiler/parser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down
9 changes: 9 additions & 0 deletions tests/baselines/reference/newLineInTypeofInstantiation.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
//// [newLineInTypeofInstantiation.ts]
interface Example {
(a: number): typeof a

<T>(): void
}


//// [newLineInTypeofInstantiation.js]
12 changes: 12 additions & 0 deletions tests/baselines/reference/newLineInTypeofInstantiation.symbols
Original file line number Diff line number Diff line change
@@ -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))
}

9 changes: 9 additions & 0 deletions tests/baselines/reference/newLineInTypeofInstantiation.types
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
=== tests/cases/compiler/newLineInTypeofInstantiation.ts ===
interface Example {
(a: number): typeof a
>a : number
>a : number

<T>(): void
}

5 changes: 5 additions & 0 deletions tests/cases/compiler/newLineInTypeofInstantiation.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
interface Example {
(a: number): typeof a

<T>(): void
}