fix: disallow all parenthesized pattern except parsing LHS (#12327)
* fix: disallow all parenthesized pattern except parsing LHS * fix: forStatement requires LHS * simplify toAssignable * add more test cases * fix: pass through isLHS on object property and assignment expression * fix: record parenthesized identifier error for LHS * remove duplicated skipped tests * fix: do not record errors on ancestry arrow head * Update packages/babel-parser/src/util/expression-scope.js Co-authored-by: Brian Ng <bng412@gmail.com> Co-authored-by: Brian Ng <bng412@gmail.com>
This commit is contained in:
@@ -278,7 +278,7 @@ export default class ExpressionParser extends LValParser {
|
||||
node.operator = operator;
|
||||
|
||||
if (this.match(tt.eq)) {
|
||||
node.left = this.toAssignable(left);
|
||||
node.left = this.toAssignable(left, /* isLHS */ true);
|
||||
refExpressionErrors.doubleProto = -1; // reset because double __proto__ is valid in assignment expression
|
||||
} else {
|
||||
node.left = left;
|
||||
@@ -842,7 +842,6 @@ export default class ExpressionParser extends LValParser {
|
||||
nodeForExtra?: ?N.Node,
|
||||
): $ReadOnlyArray<?N.Expression> {
|
||||
const elts = [];
|
||||
let innerParenStart;
|
||||
let first = true;
|
||||
const oldInFSharpPipelineDirectBody = this.state.inFSharpPipelineDirectBody;
|
||||
this.state.inFSharpPipelineDirectBody = false;
|
||||
@@ -875,12 +874,6 @@ export default class ExpressionParser extends LValParser {
|
||||
}
|
||||
}
|
||||
|
||||
// we need to make sure that if this is an async arrow functions,
|
||||
// that we don't allow inner parens inside the params
|
||||
if (this.match(tt.parenL) && !innerParenStart) {
|
||||
innerParenStart = this.state.start;
|
||||
}
|
||||
|
||||
elts.push(
|
||||
this.parseExprListItem(
|
||||
false,
|
||||
@@ -891,11 +884,6 @@ export default class ExpressionParser extends LValParser {
|
||||
);
|
||||
}
|
||||
|
||||
// we found an async arrow function so let's not allow any inner parens
|
||||
if (possibleAsyncArrow && innerParenStart && this.shouldParseAsyncArrow()) {
|
||||
this.unexpected();
|
||||
}
|
||||
|
||||
this.state.inFSharpPipelineDirectBody = oldInFSharpPipelineDirectBody;
|
||||
|
||||
return elts;
|
||||
@@ -1421,12 +1409,6 @@ export default class ExpressionParser extends LValParser {
|
||||
) {
|
||||
this.expressionScope.validateAsPattern();
|
||||
this.expressionScope.exit();
|
||||
for (const param of exprList) {
|
||||
if (param.extra && param.extra.parenthesized) {
|
||||
this.unexpected(param.extra.parenStart);
|
||||
}
|
||||
}
|
||||
|
||||
this.parseArrowExpression(arrowNode, exprList, false);
|
||||
return arrowNode;
|
||||
}
|
||||
@@ -2056,7 +2038,7 @@ export default class ExpressionParser extends LValParser {
|
||||
params: N.Expression[],
|
||||
trailingCommaPos: ?number,
|
||||
): void {
|
||||
node.params = this.toAssignableList(params, trailingCommaPos);
|
||||
node.params = this.toAssignableList(params, trailingCommaPos, false);
|
||||
}
|
||||
|
||||
parseFunctionBodyAndFinish(
|
||||
|
||||
Reference in New Issue
Block a user