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:
parent
1440d97d9c
commit
a3f00896f7
@ -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(
|
path.replaceWith(
|
||||||
t.logicalExpression(
|
t.logicalExpression(
|
||||||
operator.slice(0, -1),
|
operator.slice(0, -1),
|
||||||
lhs,
|
lhs,
|
||||||
t.assignmentExpression("=", left, rightExpression),
|
t.assignmentExpression("=", left, right),
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
|
|||||||
@ -4,6 +4,6 @@ a ||= function () {};
|
|||||||
b &&= function () {};
|
b &&= function () {};
|
||||||
c ??= function () {};
|
c ??= function () {};
|
||||||
|
|
||||||
expect(a.name).toBe("");
|
expect(a.name).toBe("a");
|
||||||
expect(b.name).toBe("");
|
expect(b.name).toBe("b");
|
||||||
expect(c.name).toBe("");
|
expect(c.name).toBe("c");
|
||||||
|
|||||||
@ -1,4 +1,4 @@
|
|||||||
var a;
|
var a;
|
||||||
a || (a = (0, function () {}));
|
a || (a = function () {});
|
||||||
a && (a = (0, function () {}));
|
a && (a = function () {});
|
||||||
a ?? (a = (0, function () {}));
|
a ?? (a = function () {});
|
||||||
|
|||||||
@ -4,6 +4,6 @@ a ||= () => {};
|
|||||||
b &&= () => {};
|
b &&= () => {};
|
||||||
c ??= () => {};
|
c ??= () => {};
|
||||||
|
|
||||||
expect(a.name).toBe("");
|
expect(a.name).toBe("a");
|
||||||
expect(b.name).toBe("");
|
expect(b.name).toBe("b");
|
||||||
expect(c.name).toBe("");
|
expect(c.name).toBe("c");
|
||||||
|
|||||||
@ -1,4 +1,4 @@
|
|||||||
var a;
|
var a;
|
||||||
a || (a = (0, () => {}));
|
a || (a = () => {});
|
||||||
a && (a = (0, () => {}));
|
a && (a = () => {});
|
||||||
a ?? (a = (0, () => {}));
|
a ?? (a = () => {});
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user