Skip to content

Commit

Permalink
replace hardcoded logical assignment operators with constant
Browse files Browse the repository at this point in the history
Replace a hardcoded check for logical assignment operators with the
LOGICAL_OPERATORS constant in
plugin-proposal-logical-assignment-operators.

Refs: babel#11702 (comment)
  • Loading branch information
ryzokuken committed Jun 11, 2020
1 parent f781b05 commit ef2cb29
Showing 1 changed file with 3 additions and 2 deletions.
Expand Up @@ -13,7 +13,8 @@ export default declare(api => {
AssignmentExpression(path) {
const { node, scope } = path;
const { operator, left, right } = node;
if (operator !== "||=" && operator !== "&&=" && operator !== "??=") {
const operatorTrunc = operator.slice(0, -1);
if (!t.LOGICAL_OPERATORS.includes(operatorTrunc)) {
return;
}

Expand Down Expand Up @@ -41,7 +42,7 @@ export default declare(api => {

path.replaceWith(
t.logicalExpression(
operator.slice(0, -1),
operatorTrunc,
lhs,
t.assignmentExpression("=", left, right),
),
Expand Down

0 comments on commit ef2cb29

Please sign in to comment.