Infer names of anonymous functions in logical assignments (#11658)

This is a partial revert of #11370, updating the tests to match the [new consensus](https://github.com/babel/proposals/issues/66#issuecomment-636984546).
This commit is contained in:
Justin Ridgewell 2020-06-03 17:23:40 -04:00 committed by GitHub
parent 1440d97d9c
commit a3f00896f7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 13 additions and 18 deletions

View File

@ -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),
),
);
},

View File

@ -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");

View File

@ -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 () {});

View File

@ -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");

View File

@ -1,4 +1,4 @@
var a;
a || (a = (0, () => {}));
a && (a = (0, () => {}));
a ?? (a = (0, () => {}));
a || (a = () => {});
a && (a = () => {});
a ?? (a = () => {});