Skip to content

Commit

Permalink
refactor: simplify estree overwritten checkDuplicateProto
Browse files Browse the repository at this point in the history
  • Loading branch information
JLHwung committed May 31, 2020
1 parent f534262 commit 3a85c92
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 25 deletions.
2 changes: 1 addition & 1 deletion packages/babel-parser/src/parser/expression.js
Expand Up @@ -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
) {
Expand Down
27 changes: 3 additions & 24 deletions packages/babel-parser/src/plugins/estree.js
Expand Up @@ -148,32 +148,11 @@ export default (superClass: Class<Parser>): Class<Parser> =>
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 {
Expand Down

0 comments on commit 3a85c92

Please sign in to comment.