Skip to content

Commit 2925fcf

Browse files
committed
Try doing this instead in the parser
1 parent 728c9b4 commit 2925fcf

File tree

3 files changed

+10
-8
lines changed

3 files changed

+10
-8
lines changed

src/compiler/checker.ts

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -28912,14 +28912,7 @@ namespace ts {
2891228912
return nonNullType;
2891328913
}
2891428914

28915-
function checkGrammarPropertyAccessExpression(node: PropertyAccessExpression) {
28916-
if (node.expression.kind === SyntaxKind.ExpressionWithTypeArguments) {
28917-
grammarErrorOnNode(node.name, Diagnostics.Instantiation_expression_cannot_be_followed_by_property_access);
28918-
}
28919-
}
28920-
2892128915
function checkPropertyAccessExpression(node: PropertyAccessExpression, checkMode: CheckMode | undefined) {
28922-
checkGrammarPropertyAccessExpression(node);
2892328916
return node.flags & NodeFlags.OptionalChain ? checkPropertyAccessChain(node as PropertyAccessChain, checkMode) :
2892428917
checkPropertyAccessExpressionOrQualifiedName(node, node.expression, checkNonNullExpression(node.expression), node.name, checkMode);
2892528918
}

src/compiler/parser.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5646,6 +5646,9 @@ namespace ts {
56465646
if (isOptionalChain && isPrivateIdentifier(propertyAccess.name)) {
56475647
parseErrorAtRange(propertyAccess.name, Diagnostics.An_optional_chain_cannot_contain_private_identifiers);
56485648
}
5649+
else if (isExpressionWithTypeArguments(expression)) {
5650+
parseErrorAtRange(propertyAccess.name, Diagnostics.Instantiation_expression_cannot_be_followed_by_property_access);
5651+
}
56495652
return finishNode(propertyAccess, pos);
56505653
}
56515654

tests/baselines/reference/instantiationExpressionErrors.errors.txt

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
tests/cases/conformance/types/typeParameters/typeArgumentLists/instantiationExpressionErrors.ts(7,22): error TS1477: Instantiation expression cannot be followed by property access.
2+
tests/cases/conformance/types/typeParameters/typeArgumentLists/instantiationExpressionErrors.ts(8,22): error TS1477: Instantiation expression cannot be followed by property access.
13
tests/cases/conformance/types/typeParameters/typeArgumentLists/instantiationExpressionErrors.ts(13,12): error TS2365: Operator '>' cannot be applied to types 'boolean' and 'string[]'.
24
tests/cases/conformance/types/typeParameters/typeArgumentLists/instantiationExpressionErrors.ts(13,14): error TS2693: 'number' only refers to a type, but is being used as a value here.
35
tests/cases/conformance/types/typeParameters/typeArgumentLists/instantiationExpressionErrors.ts(18,12): error TS2365: Operator '>' cannot be applied to types 'boolean' and 'number'.
@@ -14,15 +16,19 @@ tests/cases/conformance/types/typeParameters/typeArgumentLists/instantiationExpr
1416
tests/cases/conformance/types/typeParameters/typeArgumentLists/instantiationExpressionErrors.ts(45,12): error TS2365: Operator '>' cannot be applied to types 'boolean' and 'number'.
1517

1618

17-
==== tests/cases/conformance/types/typeParameters/typeArgumentLists/instantiationExpressionErrors.ts (14 errors) ====
19+
==== tests/cases/conformance/types/typeParameters/typeArgumentLists/instantiationExpressionErrors.ts (16 errors) ====
1820
declare let f: { <T>(): T, g<U>(): U };
1921

2022
// Type arguments in member expressions
2123

2224
const a1 = f<number>; // { (): number; g<U>(): U; }
2325
const a2 = f.g<number>; // () => number
2426
const a3 = f<number>.g; // <U>() => U
27+
~
28+
!!! error TS1477: Instantiation expression cannot be followed by property access.
2529
const a4 = f<number>.g<number>; // () => number
30+
~
31+
!!! error TS1477: Instantiation expression cannot be followed by property access.
2632
const a5 = f['g']<number>; // () => number
2733

2834
// `[` is an expression starter and cannot immediately follow a type argument list

0 commit comments

Comments
 (0)