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: port checkLVal early return for method in object pattern
  • Loading branch information
JLHwung committed Nov 19, 2020
commit 356c1969b19cf8b06868ebb3c205c9881a1adbe6
10 changes: 8 additions & 2 deletions packages/babel-parser/src/plugins/estree.js
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,12 @@ export default (superClass: Class<Parser>): Class<Parser> =>
switch (expr.type) {
case "ObjectPattern":
expr.properties.forEach(prop => {
// 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) {
return;
}
this.checkLVal(
prop.type === "Property" ? prop.value : prop,
"object destructuring pattern",
Expand Down Expand Up @@ -351,9 +357,9 @@ export default (superClass: Class<Parser>): Class<Parser> =>

toAssignableObjectExpressionProp(prop: N.Node, ...args) {
if (prop.kind === "get" || prop.kind === "set") {
throw this.raise(prop.key.start, Errors.PatternHasAccessor);
this.raise(prop.key.start, Errors.PatternHasAccessor);
} else if (prop.method) {
throw this.raise(prop.key.start, Errors.PatternHasMethod);
this.raise(prop.key.start, Errors.PatternHasMethod);
} else {
super.toAssignableObjectExpressionProp(prop, ...args);
}
Expand Down