diff --git a/packages/babel-plugin-proposal-logical-assignment-operators/src/index.js b/packages/babel-plugin-proposal-logical-assignment-operators/src/index.js index 173db1494648..813dcd761f7c 100644 --- a/packages/babel-plugin-proposal-logical-assignment-operators/src/index.js +++ b/packages/babel-plugin-proposal-logical-assignment-operators/src/index.js @@ -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), ), ); }, diff --git a/packages/babel-plugin-proposal-logical-assignment-operators/test/fixtures/logical-assignment/anonymous-functions-exec/exec.js b/packages/babel-plugin-proposal-logical-assignment-operators/test/fixtures/logical-assignment/anonymous-functions-exec/exec.js index 2b41f3380fdd..26c93bb47f7c 100644 --- a/packages/babel-plugin-proposal-logical-assignment-operators/test/fixtures/logical-assignment/anonymous-functions-exec/exec.js +++ b/packages/babel-plugin-proposal-logical-assignment-operators/test/fixtures/logical-assignment/anonymous-functions-exec/exec.js @@ -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"); diff --git a/packages/babel-plugin-proposal-logical-assignment-operators/test/fixtures/logical-assignment/anonymous-functions-transform/output.js b/packages/babel-plugin-proposal-logical-assignment-operators/test/fixtures/logical-assignment/anonymous-functions-transform/output.js index 2c6a0cfa8498..ef1cdb8363f2 100644 --- a/packages/babel-plugin-proposal-logical-assignment-operators/test/fixtures/logical-assignment/anonymous-functions-transform/output.js +++ b/packages/babel-plugin-proposal-logical-assignment-operators/test/fixtures/logical-assignment/anonymous-functions-transform/output.js @@ -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 () {}); diff --git a/packages/babel-plugin-proposal-logical-assignment-operators/test/fixtures/logical-assignment/arrow-functions-exec/exec.js b/packages/babel-plugin-proposal-logical-assignment-operators/test/fixtures/logical-assignment/arrow-functions-exec/exec.js index ea0c9127310e..9c9e47ceb1c2 100644 --- a/packages/babel-plugin-proposal-logical-assignment-operators/test/fixtures/logical-assignment/arrow-functions-exec/exec.js +++ b/packages/babel-plugin-proposal-logical-assignment-operators/test/fixtures/logical-assignment/arrow-functions-exec/exec.js @@ -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"); diff --git a/packages/babel-plugin-proposal-logical-assignment-operators/test/fixtures/logical-assignment/arrow-functions-transform/output.js b/packages/babel-plugin-proposal-logical-assignment-operators/test/fixtures/logical-assignment/arrow-functions-transform/output.js index dab2ad853771..d70125cf8076 100644 --- a/packages/babel-plugin-proposal-logical-assignment-operators/test/fixtures/logical-assignment/arrow-functions-transform/output.js +++ b/packages/babel-plugin-proposal-logical-assignment-operators/test/fixtures/logical-assignment/arrow-functions-transform/output.js @@ -1,4 +1,4 @@ var a; -a || (a = (0, () => {})); -a && (a = (0, () => {})); -a ?? (a = (0, () => {})); +a || (a = () => {}); +a && (a = () => {}); +a ?? (a = () => {});