mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-05-15 12:51:30 -05:00
Parse error on private identifier optional chain (#35987)
Previously, this error was reported in the checker, so JS files with checkJs: false were not erroring on this invalid syntax.
This commit is contained in:
committed by
Daniel Rosenwasser
parent
9fbcdb1edb
commit
f84b2d20a9
@@ -23234,10 +23234,6 @@ namespace ts {
|
||||
const assignmentKind = getAssignmentTargetKind(node);
|
||||
const apparentType = getApparentType(assignmentKind !== AssignmentKind.None || isMethodAccessForCall(node) ? getWidenedType(leftType) : leftType);
|
||||
if (isPrivateIdentifier(right)) {
|
||||
if (isOptionalChain(node)) {
|
||||
grammarErrorOnNode(right, Diagnostics.An_optional_chain_cannot_contain_private_identifiers);
|
||||
return anyType;
|
||||
}
|
||||
checkExternalEmitHelpers(node, ExternalEmitHelpers.ClassPrivateFieldGet);
|
||||
}
|
||||
const isAnyLike = isTypeAny(apparentType) || apparentType === silentNeverType;
|
||||
|
||||
@@ -4680,10 +4680,12 @@ namespace ts {
|
||||
const propertyAccess = <PropertyAccessExpression>createNode(SyntaxKind.PropertyAccessExpression, expression.pos);
|
||||
propertyAccess.expression = expression;
|
||||
propertyAccess.questionDotToken = questionDotToken;
|
||||
// checker will error on private identifiers in optional chains, so don't have to catch them here
|
||||
propertyAccess.name = parseRightSideOfDot(/*allowIdentifierNames*/ true, /*allowPrivateIdentifiers*/ true);
|
||||
if (questionDotToken || expression.flags & NodeFlags.OptionalChain) {
|
||||
propertyAccess.flags |= NodeFlags.OptionalChain;
|
||||
if (isPrivateIdentifier(propertyAccess.name)) {
|
||||
parseErrorAtRange(propertyAccess.name, Diagnostics.An_optional_chain_cannot_contain_private_identifiers);
|
||||
}
|
||||
}
|
||||
return finishNode(propertyAccess);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user