Skip to content

Commit

Permalink
feature: @putout/plugin-remove-useless-spread: object: inside call
Browse files Browse the repository at this point in the history
  • Loading branch information
coderaiser committed Jun 19, 2024
1 parent 974c21b commit b3881cc
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
const result = chooseMinify(bundle)(fixtureFrom, options);

chooseMinify(bundle)(fixtureFrom, {
a,
...options,
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
const result = chooseMinify(bundle)(fixtureFrom, {
...options,
});

chooseMinify(bundle)(fixtureFrom, {
a,
...options,
});
7 changes: 6 additions & 1 deletion packages/plugin-remove-useless-spread/lib/object/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,14 @@ const {types} = require('putout');
const {
isCallExpression,
isReturnStatement,
isSpreadElement,
} = types;

module.exports.report = () => `Avoid useless spread '...'`;

module.exports.filter = (path) => {
const [first] = path.node.properties;
const {node, parentPath} = path;
const [first] = node.properties;

const {
comments,
Expand All @@ -22,6 +24,9 @@ module.exports.filter = (path) => {
if (trailingComments?.length)
return false;

if (isCallExpression(parentPath) && isSpreadElement(first))
return true;

if (isCallExpression(first.argument))
return true;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,11 @@ test('plugin-remove-useless-spread: object: transform: object', (t) => {
t.end();
});

test('plugin-remove-useless-spread: object: transform: call', (t) => {
t.transform('call');
t.end();
});

test('plugin-remove-useless-spread: object: transform: return', (t) => {
t.transform('return');
t.end();
Expand Down

0 comments on commit b3881cc

Please sign in to comment.