fix: implement early errors for record and tuple (#11652)

This commit is contained in:
Huáng Jùnliàng
2020-06-19 20:35:27 -04:00
committed by GitHub
parent 2787ee2f96
commit 30835f14db
15 changed files with 307 additions and 43 deletions

View File

@@ -143,37 +143,17 @@ export default (superClass: Class<Parser>): Class<Parser> =>
}
}
checkDuplicatedProto(
checkProto(
prop: N.ObjectMember | N.SpreadElement,
isRecord: boolean,
protoRef: { used: boolean },
refExpressionErrors: ?ExpressionErrors,
): void {
if (
prop.type === "SpreadElement" ||
prop.computed ||
prop.method ||
// $FlowIgnore
prop.shorthand
) {
// $FlowIgnore: check prop.method and fallback to super method
if (prop.method) {
return;
}
const key = prop.key;
// It is either an Identifier or a String/NumericLiteral
const name = key.type === "Identifier" ? key.name : String(key.value);
if (name === "__proto__" && prop.kind === "init") {
// Store the first redefinition's position
if (protoRef.used) {
if (refExpressionErrors?.doubleProto === -1) {
refExpressionErrors.doubleProto = key.start;
} else {
this.raise(key.start, Errors.DuplicateProto);
}
}
protoRef.used = true;
}
super.checkProto(prop, isRecord, protoRef, refExpressionErrors);
}
isValidDirective(stmt: N.Statement): boolean {