logical-assignment: Do not assign names to anonymous functions (#11370)

This commit is contained in:
Arun Kumar Mohan
2020-05-05 09:00:41 -05:00
committed by GitHub
parent 812f3750c8
commit a8061ae7d8
16 changed files with 84 additions and 1 deletions

View File

@@ -39,11 +39,16 @@ export default declare(api => {
}
}
const isRHSAnonymousFunction = t.isFunction(right, { id: null });
const rightExpression = isRHSAnonymousFunction
? t.sequenceExpression([t.numericLiteral(0), right])
: right;
path.replaceWith(
t.logicalExpression(
operator.slice(0, -1),
lhs,
t.assignmentExpression("=", left, right),
t.assignmentExpression("=", left, rightExpression),
),
);
},