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:
Joey Watts
2020-01-07 19:00:15 -05:00
committed by Daniel Rosenwasser
parent 9fbcdb1edb
commit f84b2d20a9
8 changed files with 74 additions and 8 deletions

View File

@@ -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;

View File

@@ -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);
}