Skip to content

Commit

Permalink
Perform NamedEvaluation of Anonymous Functions in Logical Assignment
Browse files Browse the repository at this point in the history
This is a partial revert of babel#11370, updating the tests to match the [new consensus](babel/proposals#66 (comment)).
  • Loading branch information
jridgewell committed Jun 1, 2020
1 parent 1440d97 commit f62ed55
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 18 deletions.
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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");
Original file line number Diff line number Diff line change
@@ -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 () {});
Original file line number Diff line number Diff line change
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");
Original file line number Diff line number Diff line change
@@ -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 f62ed55

Please sign in to comment.