Skip to content

Commit

Permalink
fix(logical-assignment): Do not assign names to anonymous functions
Browse files Browse the repository at this point in the history
  • Loading branch information
arku committed Apr 3, 2020
1 parent 2c31587 commit cbc73c0
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 7 deletions.
Expand Up @@ -39,13 +39,26 @@ export default declare(api => {
}
}

path.replaceWith(
t.logicalExpression(
operator.slice(0, -1),
lhs,
t.assignmentExpression("=", left, right),
),
);
const isRHSAnonymousFunction = t.isFunctionExpression(right, {
id: null,
});
if (isRHSAnonymousFunction && operator === "??=") {
path.replaceWith(
t.assignmentExpression(
"=",
lhs,
t.logicalExpression("??", left, right),
),
);
} else {
path.replaceWith(
t.logicalExpression(
operator.slice(0, -1),
lhs,
t.assignmentExpression("=", left, right),
),
);
}
},
},
};
Expand Down
@@ -0,0 +1,2 @@
var f;
console.log((f ??= function () {}).name);
@@ -0,0 +1,3 @@
{
"plugins": ["proposal-logical-assignment-operators"]
}
@@ -0,0 +1,2 @@
var f;
console.log((f = f ?? function () {}).name);

0 comments on commit cbc73c0

Please sign in to comment.