@putout/operate
Advanced tools
Comparing version 8.9.0 to 8.9.1
@@ -21,2 +21,3 @@ 'use strict'; | ||
const {compute} = require('./compute'); | ||
const {remove} = require('./remove'); | ||
const {getExportDefault} = require('./get-export-default'); | ||
@@ -27,6 +28,3 @@ const { | ||
} = require('./properties'); | ||
const { | ||
assign, | ||
entries, | ||
} = Object; | ||
const {assign} = Object; | ||
@@ -117,49 +115,4 @@ module.exports.getBinding = getBinding; | ||
const isOneDeclaration = ({node}) => node.declarations.length === 1; | ||
module.exports.remove = remove; | ||
const getComments = (path) => { | ||
const {comments} = path.node; | ||
if (comments?.length) | ||
return comments; | ||
const {parentPath} = path; | ||
if (path.isVariableDeclarator() && isOneDeclaration(parentPath)) { | ||
return parentPath.node.comments; | ||
} | ||
return []; | ||
}; | ||
const getPrevSibling = (path) => { | ||
if (!path.isVariableDeclarator()) | ||
return path.getPrevSibling(); | ||
return path.parentPath.getPrevSibling(); | ||
}; | ||
module.exports.remove = (path) => { | ||
const programBlock = path.scope.getProgramParent().block; | ||
const prev = getPrevSibling(path); | ||
if (path.scope.block === programBlock && !prev.node) | ||
programBlock.comments = getComments(path); | ||
if (path.parentPath.isArrayPattern()) { | ||
const elements = path.parentPath.get('elements'); | ||
for (const [index, el] of entries(elements)) { | ||
if (el === path) { | ||
path.parentPath.node.elements[index] = null; | ||
break; | ||
} | ||
} | ||
return; | ||
} | ||
path.remove(); | ||
}; | ||
module.exports.getPathAfterImports = (body) => { | ||
@@ -166,0 +119,0 @@ const n = body.length; |
{ | ||
"name": "@putout/operate", | ||
"version": "8.9.0", | ||
"version": "8.9.1", | ||
"type": "commonjs", | ||
@@ -5,0 +5,0 @@ "author": "coderaiser <mnemonic.enemy@gmail.com> (https://github.com/coderaiser)", |
17400
10
337