Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Try doing this instead in the parser
  • Loading branch information
jakebailey committed Jun 22, 2022
commit 2925fcf6433ddd36909b934d0612826548ac5b1a
7 changes: 0 additions & 7 deletions src/compiler/checker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28912,14 +28912,7 @@ namespace ts {
return nonNullType;
}

function checkGrammarPropertyAccessExpression(node: PropertyAccessExpression) {
if (node.expression.kind === SyntaxKind.ExpressionWithTypeArguments) {
grammarErrorOnNode(node.name, Diagnostics.Instantiation_expression_cannot_be_followed_by_property_access);
}
}

function checkPropertyAccessExpression(node: PropertyAccessExpression, checkMode: CheckMode | undefined) {
checkGrammarPropertyAccessExpression(node);
return node.flags & NodeFlags.OptionalChain ? checkPropertyAccessChain(node as PropertyAccessChain, checkMode) :
checkPropertyAccessExpressionOrQualifiedName(node, node.expression, checkNonNullExpression(node.expression), node.name, checkMode);
}
Expand Down
3 changes: 3 additions & 0 deletions src/compiler/parser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5646,6 +5646,9 @@ namespace ts {
if (isOptionalChain && isPrivateIdentifier(propertyAccess.name)) {
parseErrorAtRange(propertyAccess.name, Diagnostics.An_optional_chain_cannot_contain_private_identifiers);
}
else if (isExpressionWithTypeArguments(expression)) {
parseErrorAtRange(propertyAccess.name, Diagnostics.Instantiation_expression_cannot_be_followed_by_property_access);
}
return finishNode(propertyAccess, pos);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
tests/cases/conformance/types/typeParameters/typeArgumentLists/instantiationExpressionErrors.ts(7,22): error TS1477: Instantiation expression cannot be followed by property access.
tests/cases/conformance/types/typeParameters/typeArgumentLists/instantiationExpressionErrors.ts(8,22): error TS1477: Instantiation expression cannot be followed by property access.
tests/cases/conformance/types/typeParameters/typeArgumentLists/instantiationExpressionErrors.ts(13,12): error TS2365: Operator '>' cannot be applied to types 'boolean' and 'string[]'.
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.
tests/cases/conformance/types/typeParameters/typeArgumentLists/instantiationExpressionErrors.ts(18,12): error TS2365: Operator '>' cannot be applied to types 'boolean' and 'number'.
Expand All @@ -14,15 +16,19 @@ tests/cases/conformance/types/typeParameters/typeArgumentLists/instantiationExpr
tests/cases/conformance/types/typeParameters/typeArgumentLists/instantiationExpressionErrors.ts(45,12): error TS2365: Operator '>' cannot be applied to types 'boolean' and 'number'.


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

// Type arguments in member expressions

const a1 = f<number>; // { (): number; g<U>(): U; }
const a2 = f.g<number>; // () => number
const a3 = f<number>.g; // <U>() => U
~
!!! error TS1477: Instantiation expression cannot be followed by property access.
const a4 = f<number>.g<number>; // () => number
~
!!! error TS1477: Instantiation expression cannot be followed by property access.
const a5 = f['g']<number>; // () => number

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