Skip to content

Commit

Permalink
Infer names of anonymous functions in logical assignments (#11658)
Browse files Browse the repository at this point in the history
This is a partial revert of #11370, updating the tests to match the [new consensus](babel/proposals#66 (comment)).
  • Loading branch information
jridgewell committed Jun 3, 2020
1 parent 1440d97 commit a3f0089
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 18 deletions.
Expand Up @@ -39,16 +39,11 @@ 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, rightExpression),
t.assignmentExpression("=", left, right),
),
);
},
Expand Down
Expand Up @@ -4,6 +4,6 @@ a ||= function () {};
b &&= function () {};
c ??= function () {};

expect(a.name).toBe("");
expect(b.name).toBe("");
expect(c.name).toBe("");
expect(a.name).toBe("a");
expect(b.name).toBe("b");
expect(c.name).toBe("c");
@@ -1,4 +1,4 @@
var a;
a || (a = (0, function () {}));
a && (a = (0, function () {}));
a ?? (a = (0, function () {}));
a || (a = function () {});
a && (a = function () {});
a ?? (a = function () {});
Expand Up @@ -4,6 +4,6 @@ a ||= () => {};
b &&= () => {};
c ??= () => {};

expect(a.name).toBe("");
expect(b.name).toBe("");
expect(c.name).toBe("");
expect(a.name).toBe("a");
expect(b.name).toBe("b");
expect(c.name).toBe("c");
@@ -1,4 +1,4 @@
var a;
a || (a = (0, () => {}));
a && (a = (0, () => {}));
a ?? (a = (0, () => {}));
a || (a = () => {});
a && (a = () => {});
a ?? (a = () => {});

0 comments on commit a3f0089

Please sign in to comment.