@putout/operate
Advanced tools
Comparing version 8.8.0 to 8.9.0
@@ -15,10 +15,18 @@ 'use strict'; | ||
const {getBinding, getBindingPath} = require('./get-binding'); | ||
const { | ||
getBinding, | ||
getBindingPath, | ||
} = require('./get-binding'); | ||
const {extract} = require('./extract'); | ||
const {compute} = require('./compute'); | ||
const {getExportDefault} = require('./get-export-default'); | ||
const {getProperty, getProperties} = require('./properties'); | ||
const { | ||
getProperty, | ||
getProperties, | ||
} = require('./properties'); | ||
const { | ||
assign, | ||
entries, | ||
} = Object; | ||
const {assign} = Object; | ||
module.exports.getBinding = getBinding; | ||
@@ -30,9 +38,9 @@ module.exports.getBindingPath = getBindingPath; | ||
module.exports.getExportDefault = getExportDefault; | ||
module.exports.getProperty = getProperty; | ||
module.exports.getProperties = getProperties; | ||
module.exports.toExpression = toExpression; | ||
module.exports.toExpression = toExpression; | ||
function toExpression(el) { | ||
const {type} = el; | ||
const ignore = [ | ||
@@ -52,6 +60,9 @@ 'ObjectProperty', | ||
function replaceWith(path, node) { | ||
if (path?.parentPath?.isExpressionStatement?.() && !path.parentPath.isProgram()) | ||
if (path?.parentPath?.isExpressionStatement() && !path.parentPath.isProgram()) | ||
path = path.parentPath; | ||
const {comments, loc} = path.node; | ||
const { | ||
comments, | ||
loc, | ||
} = path.node; | ||
const {currentPath} = maybeBody(path, node); | ||
@@ -73,5 +84,3 @@ | ||
const newNodes = nodes | ||
.filter(Boolean) | ||
.map(toExpression); | ||
const newNodes = nodes.filter(Boolean).map(toExpression); | ||
@@ -91,3 +100,2 @@ const {currentPath} = maybeBody(path); | ||
const {comments} = path.node; | ||
path.insertAfter(node); | ||
@@ -143,2 +151,15 @@ path.node.comments = comments; | ||
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(); | ||
@@ -180,3 +201,5 @@ }; | ||
parentPath.node.body = BlockStatement([ExpressionStatement(path.node)]); | ||
parentPath.node.body = BlockStatement([ | ||
ExpressionStatement(path.node), | ||
]); | ||
@@ -187,2 +210,1 @@ return { | ||
} | ||
{ | ||
"name": "@putout/operate", | ||
"version": "8.8.0", | ||
"version": "8.9.0", | ||
"type": "commonjs", | ||
@@ -9,3 +9,2 @@ "author": "coderaiser <mnemonic.enemy@gmail.com> (https://github.com/coderaiser)", | ||
"main": "lib/operate.js", | ||
"commitType": "colon", | ||
"release": false, | ||
@@ -42,3 +41,3 @@ "tag": false, | ||
"eslint-plugin-n": "^15.2.4", | ||
"eslint-plugin-putout": "^16.0.0", | ||
"eslint-plugin-putout": "^17.0.0", | ||
"just-camel-case": "^4.0.2", | ||
@@ -45,0 +44,0 @@ "lerna": "^6.0.1", |
17166
329