Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make sure babel parser throws exactly same recoverable errors when estree plugin is enabled #12375

Merged
merged 13 commits into from
Dec 3, 2020
Merged
Prev Previous commit
Next Next commit
fix: early return for __proto__ in accessors
  • Loading branch information
JLHwung committed Nov 19, 2020
commit 105c2cc469cfdca3135f50d6fba620a8913cff02
15 changes: 8 additions & 7 deletions packages/babel-parser/src/plugins/estree.js
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ export default (superClass: Class<Parser>): Class<Parser> =>
// If we find here a method or accessor, it's because this was originally
// an ObjectExpression which has then been converted.
// toAssignable already reported this error with a nicer message.
if (prop.kind === "get" || prop.kind === "set" || prop.method) {
if (this.isMethodOrAccessor(prop)) {
return;
}
this.checkLVal(
Expand All @@ -146,17 +146,18 @@ export default (superClass: Class<Parser>): Class<Parser> =>
}
}

isMethodOrAccessor(node: N.Node): boolean {
return node.method || node.kind === "get" || node.kind === "set";
}

checkProto(
prop: N.ObjectMember | N.SpreadElement,
isRecord: boolean,
protoRef: { used: boolean },
refExpressionErrors: ?ExpressionErrors,
...args: [boolean, { used: boolean }, ?ExpressionErrors]
): void {
// $FlowIgnore: check prop.method and fallback to super method
if (prop.method) {
if (this.isMethodOrAccessor(prop)) {
return;
}
super.checkProto(prop, isRecord, protoRef, refExpressionErrors);
super.checkProto(prop, ...args);
}

isValidDirective(stmt: N.Statement): boolean {
Expand Down