Skip to content

Commit

Permalink
feature: @putout/operate: insertAfter: wrap ExpressionStatement when …
Browse files Browse the repository at this point in the history
…current path is Statement and node not
  • Loading branch information
coderaiser committed Apr 29, 2024
1 parent fabf160 commit 2a817e8
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 11 deletions.
10 changes: 0 additions & 10 deletions packages/operate/.eslintrc.json

This file was deleted.

5 changes: 5 additions & 0 deletions packages/operate/eslint.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
'use strict';

const {safeAlign} = require('eslint-plugin-putout/config');

module.exports = safeAlign;
6 changes: 5 additions & 1 deletion packages/operate/lib/operate.js
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,11 @@ module.exports.insertAfter = (path, node) => {
if (node.trailingComments)
delete node.trailingComments;

path.insertAfter(node);
if (isStatement(path) && !isStatement(node))
path.insertAfter(ExpressionStatement(node));
else
path.insertAfter(node);

path.node.comments = comments;
};

Expand Down
21 changes: 21 additions & 0 deletions packages/operate/test/operate.js
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,27 @@ test('putout: operate: insertAfter', (t) => {
t.end();
});

test('putout: operate: insertAfter: not ExpressionStatement', (t) => {
const node = {
type: 'MemberExpression',
};

const insertAfter = stub();

const path = {
type: 'ClassDeclaration',
node: {},
insertAfter,
};

operate.insertAfter(path, node);
const {args} = insertAfter;
const [[result]] = args;

t.equal(result.type, 'ExpressionStatement');
t.end();
});

test('putout: operate: insertBefore', (t) => {
const node = {};
const insertBefore = stub();
Expand Down

0 comments on commit 2a817e8

Please sign in to comment.