New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More โ†’
Socket
Sign inDemoInstall
Socket

@putout/operate

Package Overview
Dependencies
Maintainers
1
Versions
107
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@putout/operate - npm Package Compare versions

Comparing version

to
12.10.0

lib/replace-with/fixture/replace-with-multiple-leading-comment-fix.js

10

lib/extract.js

@@ -57,3 +57,11 @@ 'use strict';

const nodeTypes = [
'Literals', 'Identifiers', 'TemplateLiteral', 'TemplateElement', 'RegExpLiteral', 'ArrayExpression', 'MemberExpression', 'JSXAttribute', 'JSXText',
'Literals',
'Identifiers',
'TemplateLiteral',
'TemplateElement',
'RegExpLiteral',
'ArrayExpression',
'MemberExpression',
'JSXAttribute',
'JSXText',
].join(', ');

@@ -60,0 +68,0 @@

82

lib/operate.js

@@ -25,15 +25,15 @@ 'use strict';

const {
replaceWith,
replaceWithMultiple,
toExpression,
} = require('./replace-with');
const {
ExpressionStatement,
toStatement,
matchesPattern,
isBlockStatement,
isImportDeclaration,
isExportDeclaration,
isExpression,
isStatement,
BlockStatement,
} = types;
const {assign} = Object;
module.exports.getBinding = getBinding;

@@ -56,55 +56,4 @@ module.exports.getBindingPath = getBindingPath;

function toExpression(el) {
const {type} = el;
const ignore = [
'ObjectProperty',
];
if (ignore.includes(type))
return el;
if (isExpression(el))
return ExpressionStatement(el);
return toStatement(el);
}
module.exports.replaceWithMultiple = replaceWithMultiple;
function replaceWith(path, node) {
if (path?.parentPath?.isExpressionStatement() && !path.parentPath.isProgram())
path = path.parentPath;
const {comments, loc} = path.node;
const {currentPath} = maybeBody(path, node);
currentPath.replaceWith(node);
assign(currentPath.node, {
comments,
loc,
});
return currentPath;
}
module.exports.replaceWithMultiple = (path, nodes) => {
const parentComments = path.parentPath.node.comments;
const {comments} = path.node;
const newNodes = nodes
.filter(Boolean)
.map(toExpression);
const {currentPath} = maybeBody(path);
const newPath = currentPath.replaceWithMultiple(newNodes);
if (!newPath.length)
return newPath;
newPath[0].node.comments = comments || parentComments;
return newPath;
};
module.exports.insertBefore = (path, node) => {

@@ -173,18 +122,1 @@ path.insertBefore(node);

};
function maybeBody(path, node) {
const {parentPath} = path;
if (node && !isStatement(node) || isBlockStatement(node) || !parentPath?.isArrowFunctionExpression?.())
return {
currentPath: path,
};
parentPath.node.body = BlockStatement([
ExpressionStatement(path.node),
]);
return {
currentPath: parentPath.get('body.body.0'),
};
}
{
"name": "@putout/operate",
"version": "12.9.2",
"version": "12.10.0",
"type": "commonjs",

@@ -43,4 +43,4 @@ "author": "coderaiser <mnemonic.enemy@gmail.com> (https://github.com/coderaiser)",

"eslint-plugin-n": "^17.0.0",
"eslint-plugin-putout": "^22.0.0",
"just-camel-case": "^4.0.2",
"eslint-plugin-putout": "^23.0.0",
"just-camel-case": "^6.2.0",
"lerna": "^6.0.1",

@@ -47,0 +47,0 @@ "madrun": "^10.0.0",

@@ -236,3 +236,3 @@ # Operate [![NPM version][NPMIMGURL]][NPMURL] [![Coverage Status][CoverageIMGURL]][CoverageURL]

```js
const homepagePath = getProperties(__aPath, 'homepage');
const homepagePath = getProperty(__aPath, 'homepage');
```

@@ -239,0 +239,0 @@