You're Invited:Meet the Socket Team at RSAC and BSidesSF 2026, March 23–26.RSVP
Socket
Book a DemoSign in
Socket

@putout/printer

Package Overview
Dependencies
Maintainers
1
Versions
835
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@putout/printer - npm Package Compare versions

Comparing version
18.7.7
to
18.7.8
+19
lib/tokenize/expre...s-looks-like-chain/check-calls-count.js
import {types} from '@putout/babel';
import {createTypeChecker} from '#type-checker';
const {isCallExpression} = types;
export const checkCallsCount = (path, {properties}) => {
const calls = properties.filter(isCallExpression);
return checkFilteredCalls(calls);
};
const isTwoCallsWithoutName = createTypeChecker([
['-: length -> !', '=', 2],
['+: 0.name -> -'],
]);
const checkFilteredCalls = createTypeChecker([
['-', isTwoCallsWithoutName],
['+: length', '>', 1],
]);
import {types} from '@putout/babel';
import {createTypeChecker} from '#type-checker';
import {chain} from '../chain.js';
import {checkCallsCount} from './check-calls-count.js';
const hasPropertyWithComment = (properties) => {
return properties.find(hasComment);
};
const isPathGet = ([property]) => {
return isCallExpression(property, {
name: 'get',
});
};
const {
isIfStatement,
isCallExpression,
} = types;
const isPathFirstArg = ({node, parentPath}) => {
const [first] = parentPath.node.arguments;
return node === first;
};
function isPathLastArg({node, parentPath}) {
const last = parentPath.node.arguments.at(-1);
return node === last;
}
const isFirstArgOfCall = createTypeChecker([
['-: parentPath -> !CallExpression'],
['+', isPathFirstArg],
]);
const isLastArgInCall = createTypeChecker([
['-: parentPath -> !CallExpression'],
['+', isPathLastArg],
]);
const callWithRoot = (fn) => (a, {root}) => fn(root);
const isExcludedFromChain = createTypeChecker([
'+: -> UnaryExpression',
'+: -> IfStatement',
]);
const hasComment = ({type}) => type === 'CommentLine';
const isInsideMemberCall = createTypeChecker([
['-: node.object -> !Identifier'],
['-: node.property -> !Identifier'],
['+', isLastArgInCall],
['+: parentPath.parentPath -> CallExpression'],
]);
const callWithProperties = (fn) => (a, {properties}) => fn(properties);
const isFindUpIf = (path) => path.find(isIfUp);
export const isLooksLikeChain = (path) => {
const [root, properties] = chain(path);
return isLikeChain(path, {
root,
properties,
});
};
const isLikeChain = createTypeChecker([
['-', isInsideMemberCall],
['-', callWithRoot(isExcludedFromChain)],
['-', callWithProperties(isPathGet)],
['+', callWithProperties(hasPropertyWithComment)],
['-', isFindUpIf],
['-', isFirstArgOfCall],
['+', checkCallsCount],
]);
const isIfUp = (path) => {
const ifPath = path.find(isIfStatement);
let is = false;
if (!ifPath)
return is;
ifPath.get('test').traverse({
MemberExpression(currentPath) {
if (path === currentPath) {
is = true;
path.stop();
}
},
});
return is;
};
+1
-1

@@ -7,3 +7,3 @@ import {types} from '@putout/babel';

} from '#is';
import {isLooksLikeChain} from '../expressions/member-expression/is-looks-like-chain.js';
import {isLooksLikeChain} from '../expressions/member-expression/is-looks-like-chain/index.js';
import {

@@ -10,0 +10,0 @@ printTrailingComments,

import {maybeParens} from '#maybe-parens';
import {createTypeChecker} from '#type-checker';
import {maybePrintComputed} from '../object-expression/maybe-print-computed.js';
import {isLooksLikeChain} from './is-looks-like-chain.js';
import {isLooksLikeChain} from './is-looks-like-chain/index.js';

@@ -6,0 +6,0 @@ const isObjectInsideArrow = createTypeChecker([

@@ -15,3 +15,3 @@ import {types} from '@putout/babel';

import {isInsideTuple} from './is-inside-tuple.js';
import {isLooksLikeChain} from '../member-expression/is-looks-like-chain.js';
import {isLooksLikeChain} from '../member-expression/is-looks-like-chain/index.js';
import {isCommaAfterSpread} from './comma.js';

@@ -18,0 +18,0 @@ import {isMultilineOption} from '../array-expression/is.js';

import {types} from '@putout/babel';
import {createTypeChecker} from '#type-checker';
import {isLooksLikeChain} from '../../expressions/member-expression/is-looks-like-chain.js';
import {isLooksLikeChain} from '../../expressions/member-expression/is-looks-like-chain/index.js';

@@ -5,0 +5,0 @@ const {isCallExpression} = types;

{
"name": "@putout/printer",
"version": "18.7.7",
"version": "18.7.8",
"type": "module",

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

import {types} from '@putout/babel';
import {createTypeChecker} from '#type-checker';
import {chain} from './chain.js';
const hasPropertyWithComment = (properties) => {
return properties.find(hasComment);
};
const isPathGet = ([property]) => {
return isCallExpression(property, {
name: 'get',
});
};
const {
isIfStatement,
isCallExpression,
} = types;
const isPathFirstArg = ({node, parentPath}) => {
const [first] = parentPath.node.arguments;
return node === first;
};
function isPathLastArg({node, parentPath}) {
const last = parentPath.node.arguments.at(-1);
return node === last;
}
const isFirstArgOfCall = createTypeChecker([
['-: parentPath -> !CallExpression'],
['+', isPathFirstArg],
]);
const isLastArgInCall = createTypeChecker([
['-: parentPath -> !CallExpression'],
['+', isPathLastArg],
]);
const isCall = (a) => a.type === 'CallExpression';
const callWithRoot = (fn) => (a, {root}) => fn(root);
const isExcludedFromChain = createTypeChecker([
'+: -> UnaryExpression',
'+: -> IfStatement',
]);
const hasComment = ({type}) => type === 'CommentLine';
const isInsideMemberCall = createTypeChecker([
['-: node.object -> !Identifier'],
['-: node.property -> !Identifier'],
['+', isLastArgInCall],
['+: parentPath.parentPath -> CallExpression'],
]);
const callWithProperties = (fn) => (a, {properties}) => fn(properties);
const isFindUpIf = (path) => path.find(isIfUp);
const checkCallsCount = (path, {properties}) => {
const calls = properties.filter(isCall);
const [firstCall] = calls;
if (calls.length === 2 && !firstCall.name)
return false;
return calls.length > 1;
};
export const isLooksLikeChain = (path) => {
const [root, properties] = chain(path);
return isLikeChain(path, {
root,
properties,
});
};
const isLikeChain = createTypeChecker([
['-', isInsideMemberCall],
['-', callWithRoot(isExcludedFromChain)],
['-', callWithProperties(isPathGet)],
['+', callWithProperties(hasPropertyWithComment)],
['-', isFindUpIf],
['-', isFirstArgOfCall],
['+', checkCallsCount],
]);
const isIfUp = (path) => {
const ifPath = path.find(isIfStatement);
let is = false;
if (!ifPath)
return is;
ifPath.get('test').traverse({
MemberExpression(currentPath) {
if (path === currentPath) {
is = true;
path.stop();
}
},
});
return is;
};

Sorry, the diff of this file is not supported yet