diff --git a/packages/babel-parser/src/parser/expression.js b/packages/babel-parser/src/parser/expression.js index 7d8a51d1ef40..cee5d30bc0d2 100644 --- a/packages/babel-parser/src/parser/expression.js +++ b/packages/babel-parser/src/parser/expression.js @@ -85,8 +85,8 @@ export default class ExpressionParser extends LValParser { ): void { if ( prop.type === "SpreadElement" || + prop.type === "ObjectMethod" || prop.computed || - prop.kind || // $FlowIgnore prop.shorthand ) { diff --git a/packages/babel-parser/src/plugins/estree.js b/packages/babel-parser/src/plugins/estree.js index 71265770c2e3..f8021751dfcd 100644 --- a/packages/babel-parser/src/plugins/estree.js +++ b/packages/babel-parser/src/plugins/estree.js @@ -148,32 +148,11 @@ export default (superClass: Class): Class => 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.checkDuplicatedProto(prop, protoRef, refExpressionErrors); } isValidDirective(stmt: N.Statement): boolean {