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: pass through isLHS in toAssignable
  • Loading branch information
JLHwung committed Nov 19, 2020
commit 3cc4e5ece76845c0e28e54e232e909774f264367
2 changes: 1 addition & 1 deletion packages/babel-parser/src/parser/lval.js
Original file line number Diff line number Diff line change
Expand Up @@ -445,7 +445,7 @@ export default class LValParser extends NodeUtils {

case "ObjectPattern":
for (let prop of expr.properties) {
if (this.isObjectProperty(prop)) prop = prop.value;
if (prop.type === "ObjectProperty") prop = prop.value;
// If we find here an ObjectMethod, it's because this was originally
// an ObjectExpression which has then been converted.
// toAssignable already reported this error with a nicer message.
Expand Down
15 changes: 3 additions & 12 deletions packages/babel-parser/src/plugins/estree.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,6 @@ import type { Position } from "../util/location";
import { type BindingTypes } from "../util/scopeflags";
import { Errors } from "../parser/error";

function isSimpleProperty(node: N.Node): boolean {
return (
node != null &&
node.type === "Property" &&
node.kind === "init" &&
node.method === false
);
}

export default (superClass: Class<Parser>): Class<Parser> =>
class extends superClass {
estreeParseRegExpLiteral({ pattern, flags }: N.RegExpLiteral): N.Node {
Expand Down Expand Up @@ -103,7 +94,7 @@ export default (superClass: Class<Parser>): Class<Parser> =>
}

checkDeclaration(node: N.Pattern | N.ObjectProperty): void {
if (isSimpleProperty(node)) {
if (node != null && this.isObjectProperty(node)) {
this.checkDeclaration(((node: any): N.EstreeProperty).value);
} else {
super.checkDeclaration(node);
Expand Down Expand Up @@ -347,8 +338,8 @@ export default (superClass: Class<Parser>): Class<Parser> =>
}

toAssignable(node: N.Node, isLHS: boolean = false): N.Node {
if (isSimpleProperty(node)) {
this.toAssignable(node.value);
if (node != null && this.isObjectProperty(node)) {
this.toAssignable(node.value, isLHS);

return node;
}
Expand Down