@putout/operate
Advanced tools
Comparing version 8.6.1 to 8.7.0
@@ -10,2 +10,4 @@ 'use strict'; | ||
isExpression, | ||
isStatement, | ||
BlockStatement, | ||
} = require('@babel/types'); | ||
@@ -52,6 +54,7 @@ | ||
const {comments, loc} = path.node; | ||
const {currentPath} = maybeBody(path, node); | ||
path.replaceWith(node); | ||
currentPath.replaceWith(node); | ||
assign(path.node, { | ||
assign(currentPath.node, { | ||
comments, | ||
@@ -61,3 +64,3 @@ loc, | ||
return path; | ||
return currentPath; | ||
} | ||
@@ -73,3 +76,4 @@ | ||
const newPath = path.replaceWithMultiple(newNodes); | ||
const {currentPath} = maybeBody(path); | ||
const newPath = currentPath.replaceWithMultiple(newNodes); | ||
@@ -165,1 +169,16 @@ if (!newPath.length) | ||
function maybeBody(path, node) { | ||
const {parentPath} = path; | ||
if (node && !isStatement(node) || !parentPath?.isArrowFunctionExpression?.()) | ||
return { | ||
currentPath: path, | ||
}; | ||
parentPath.node.body = BlockStatement([ExpressionStatement(path.node)]); | ||
return { | ||
currentPath: parentPath.get('body.body.0'), | ||
}; | ||
} | ||
{ | ||
"name": "@putout/operate", | ||
"version": "8.6.1", | ||
"version": "8.7.0", | ||
"type": "commonjs", | ||
@@ -5,0 +5,0 @@ "author": "coderaiser <mnemonic.enemy@gmail.com> (https://github.com/coderaiser)", |
16771
306