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: #11702 (comment)
  • Loading branch information
ryzokuken committed Jul 22, 2020
1 parent 9cf68b1 commit 25bfbf4
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 25bfbf4

Please sign in to comment.