Skip to content

Commit

Permalink
remove unused contextDescription
Browse files Browse the repository at this point in the history
  • Loading branch information
JLHwung committed Jan 20, 2020
1 parent 4d0f4c1 commit 4fcf61c
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 51 deletions.
8 changes: 2 additions & 6 deletions packages/babel-parser/src/parser/expression.js
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ export default class ExpressionParser extends LValParser {
this.expectPlugin("logicalAssignment");
}
if (this.match(tt.eq)) {
node.left = this.toAssignable(left, "assignment expression");
node.left = this.toAssignable(left);
refExpressionErrors.doubleProto = -1; // reset because double __proto__ is valid in assignment expression
} else {
node.left = left;
Expand Down Expand Up @@ -1883,11 +1883,7 @@ export default class ExpressionParser extends LValParser {
params: N.Expression[],
trailingCommaPos: ?number,
): void {
node.params = this.toAssignableList(
params,
"arrow function parameters",
trailingCommaPos,
);
node.params = this.toAssignableList(params, trailingCommaPos);
}

parseFunctionBodyAndFinish(
Expand Down
26 changes: 9 additions & 17 deletions packages/babel-parser/src/parser/lval.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ export default class LValParser extends NodeUtils {
// NOTE: There is a corresponding "isAssignable" method in flow.js.
// When this one is updated, please check if also that one needs to be updated.

toAssignable(node: Node, contextDescription: string): Node {
toAssignable(node: Node): Node {
if (node) {
if (
(this.options.createParenthesizedExpressions &&
Expand Down Expand Up @@ -95,25 +95,21 @@ export default class LValParser extends NodeUtils {
break;

case "ObjectProperty":
this.toAssignable(node.value, contextDescription);
this.toAssignable(node.value);
break;

case "SpreadElement": {
this.checkToRestConversion(node);

node.type = "RestElement";
const arg = node.argument;
this.toAssignable(arg, contextDescription);
this.toAssignable(arg);
break;
}

case "ArrayExpression":
node.type = "ArrayPattern";
this.toAssignableList(
node.elements,
contextDescription,
node.extra?.trailingComma,
);
this.toAssignableList(node.elements, node.extra?.trailingComma);
break;

case "AssignmentExpression":
Expand All @@ -126,14 +122,11 @@ export default class LValParser extends NodeUtils {

node.type = "AssignmentPattern";
delete node.operator;
this.toAssignable(node.left, contextDescription);
this.toAssignable(node.left);
break;

case "ParenthesizedExpression":
node.expression = this.toAssignable(
node.expression,
contextDescription,
);
node.expression = this.toAssignable(node.expression);
break;

default:
Expand All @@ -155,15 +148,14 @@ export default class LValParser extends NodeUtils {
} else if (prop.type === "SpreadElement" && !isLast) {
this.raiseRestNotLast(prop.start);
} else {
this.toAssignable(prop, "object destructuring pattern");
this.toAssignable(prop);
}
}

// Convert list of expression atoms to binding list.

toAssignableList(
exprList: Expression[],
contextDescription: string,
trailingCommaPos?: ?number,
): $ReadOnlyArray<Pattern> {
let end = exprList.length;
Expand All @@ -174,7 +166,7 @@ export default class LValParser extends NodeUtils {
} else if (last && last.type === "SpreadElement") {
last.type = "RestElement";
const arg = last.argument;
this.toAssignable(arg, contextDescription);
this.toAssignable(arg);
if (
arg.type !== "Identifier" &&
arg.type !== "MemberExpression" &&
Expand All @@ -194,7 +186,7 @@ export default class LValParser extends NodeUtils {
for (let i = 0; i < end; i++) {
const elt = exprList[i];
if (elt) {
this.toAssignable(elt, contextDescription);
this.toAssignable(elt);
if (elt.type === "RestElement") {
this.raiseRestNotLast(elt.start);
}
Expand Down
2 changes: 1 addition & 1 deletion packages/babel-parser/src/parser/statement.js
Original file line number Diff line number Diff line change
Expand Up @@ -537,10 +537,10 @@ export default class StatementParser extends ExpressionParser {
const refExpressionErrors = new ExpressionErrors();
const init = this.parseExpression(true, refExpressionErrors);
if (this.match(tt._in) || this.isContextual("of")) {
this.toAssignable(init);
const description = this.isContextual("of")
? "for-of statement"
: "for-in statement";
this.toAssignable(init, description);
this.checkLVal(init, undefined, undefined, description);
return this.parseForIn(node, init, awaitAt);
} else {
Expand Down
6 changes: 3 additions & 3 deletions packages/babel-parser/src/plugins/estree.js
Original file line number Diff line number Diff line change
Expand Up @@ -362,14 +362,14 @@ export default (superClass: Class<Parser>): Class<Parser> =>
return (node: any);
}

toAssignable(node: N.Node, contextDescription: string): N.Node {
toAssignable(node: N.Node): N.Node {
if (isSimpleProperty(node)) {
this.toAssignable(node.value, contextDescription);
this.toAssignable(node.value);

return node;
}

return super.toAssignable(node, contextDescription);
return super.toAssignable(node);
}

toAssignableObjectExpressionProp(prop: N.Node, isLast: boolean) {
Expand Down
17 changes: 4 additions & 13 deletions packages/babel-parser/src/plugins/flow.js
Original file line number Diff line number Diff line change
Expand Up @@ -1886,7 +1886,6 @@ export default (superClass: Class<Parser>): Class<Parser> =>
// node.params is Expression[] instead of $ReadOnlyArray<Pattern> because it
// has not been converted yet.
((node.params: any): N.Expression[]),
"arrow function parameters",
node.extra?.trailingComma,
);
// Enter scope, as checkParams defines bindings
Expand Down Expand Up @@ -2090,21 +2089,17 @@ export default (superClass: Class<Parser>): Class<Parser> =>
}
}

toAssignable(node: N.Node, contextDescription: string): N.Node {
toAssignable(node: N.Node): N.Node {
if (node.type === "TypeCastExpression") {
return super.toAssignable(
this.typeCastToParameter(node),
contextDescription,
);
return super.toAssignable(this.typeCastToParameter(node));
} else {
return super.toAssignable(node, contextDescription);
return super.toAssignable(node);
}
}

// turn type casts that we found in function parameter head into type annotated params
toAssignableList(
exprList: N.Expression[],
contextDescription: string,
trailingCommaPos?: ?number,
): $ReadOnlyArray<N.Pattern> {
for (let i = 0; i < exprList.length; i++) {
Expand All @@ -2113,11 +2108,7 @@ export default (superClass: Class<Parser>): Class<Parser> =>
exprList[i] = this.typeCastToParameter(expr);
}
}
return super.toAssignableList(
exprList,
contextDescription,
trailingCommaPos,
);
return super.toAssignableList(exprList, trailingCommaPos);
}

// this is a list of nodes, from something like a call expression, we need to filter the
Expand Down
16 changes: 5 additions & 11 deletions packages/babel-parser/src/plugins/typescript/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2392,25 +2392,19 @@ export default (superClass: Class<Parser>): Class<Parser> =>
return param;
}

toAssignable(node: N.Node, contextDescription: string): N.Node {
toAssignable(node: N.Node): N.Node {
switch (node.type) {
case "TSTypeCastExpression":
return super.toAssignable(
this.typeCastToParameter(node),
contextDescription,
);
return super.toAssignable(this.typeCastToParameter(node));
case "TSParameterProperty":
return super.toAssignable(node, contextDescription);
return super.toAssignable(node);
case "TSAsExpression":
case "TSNonNullExpression":
case "TSTypeAssertion":
node.expression = this.toAssignable(
node.expression,
contextDescription,
);
node.expression = this.toAssignable(node.expression);
return node;
default:
return super.toAssignable(node, contextDescription);
return super.toAssignable(node);
}
}

Expand Down

0 comments on commit 4fcf61c

Please sign in to comment.