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.8.0
to
18.8.1
+12
lib/tokenize/expressions/object-pattern/indent.js
import {createTypeChecker} from '#type-checker';
import {
hasOptionIs,
isInsideFn,
isPrevAssignObject,
} from './is.js';
export const isIndentBeforeProperty = createTypeChecker([
['-', isInsideFn],
['+', isPrevAssignObject],
['+', hasOptionIs],
]);
+16
-37

@@ -1,41 +0,20 @@

import {types} from '@putout/babel';
import {createTypeChecker} from '#type-checker';
import {isNextAssignObject} from './is.js';
const {
isAssignmentPattern,
isArrayExpression,
isObjectExpression,
isIdentifier,
} = types;
export const calculateAssigns = (property, semantics) => {
const currentAssign = isLongAssignPattern(property, semantics);
const {right} = property.node.value;
const isArrayOrObjectRight = isArrayExpression(right) || isComplexObject(right);
const complexAssign = currentAssign && isArrayOrObjectRight;
return {
complexAssign,
};
const isMoreThenMaxPropertiesLengthInOneLineOption = (a, {semantics}) => {
const {maxPropertiesLengthInOneLine} = semantics;
return a > maxPropertiesLengthInOneLine;
};
export function isLongAssignPattern(path, semantics) {
const {key, value} = path.node;
if (!isAssignmentPattern(value))
return false;
if (!isIdentifier(key))
return true;
const {maxPropertiesLengthInOneLine} = semantics;
return key.name.length > maxPropertiesLengthInOneLine;
}
const isCoupleOption = (a, {couple}) => couple;
function isComplexObject(node) {
if (!isObjectExpression(node))
return false;
return node.properties.length;
}
const isNextAssignAndCurrentNotAssign = createTypeChecker([
['-: ->', isCoupleOption],
['+: node.value -> AssignmentPattern'],
['+: -> !', isNextAssignObject],
]);
export const isBreaklineBeforeProperty = createTypeChecker([
['-: ->', isNextAssignAndCurrentNotAssign],
['+: node.key.name.length -> !', isMoreThenMaxPropertiesLengthInOneLineOption],
]);
import {types} from '@putout/babel';
import {createTypeChecker} from '#type-checker';
import {callWithNext} from '#is';
import {
hasOptionIs,
isNextAssignObject,
isPrevAssignObject,
} from './is.js';

@@ -21,4 +27,10 @@ const {

const hasNode = (path) => path.node;
export const isCommaAfterProperty = createTypeChecker([
['+', isCoupleOption],
['+', hasOptionIs],
['+', isNextAssignObject],
['+', isPrevAssignObject],
['+', callWithNext(hasNode)],
['-: key -> -'],

@@ -29,1 +41,9 @@ ['-', isPrevAssign],

]);
export const isNewlineAfterComma = createTypeChecker([
['+', isCoupleOption],
['-: key -> -'],
['-', isPrevAssign],
['-: parentPath', isInsideForOf],
['+: node.value.right -> ObjectExpression'],
]);

@@ -17,2 +17,4 @@ import {types} from '@putout/babel';

export const hasOptionIs = (a, {is}) => is;
export const isInsideFn = (path) => {

@@ -50,2 +52,6 @@ if (isFunction(path.parentPath))

export const isNextAssignObject = callWithNext(createTypeChecker(['-: node -> -', '-: node.value -> !AssignmentPattern', '+: node.value.right -> ObjectExpression']));
export const isNextAssignObject = callWithNext(createTypeChecker([
'-: node -> -',
'-: node.value -> !AssignmentPattern',
'+: node.value.right -> ObjectExpression',
]));
import {wrongShorthand} from './wrong-shorthand.js';
import {maybeTypeAnnotation} from '../../maybe/maybe-type-annotation.js';
import {printKey} from '../object-expression/print-key.js';
import {
calculateAssigns,
isLongAssignPattern,
} from './calculate-long-assign-pattern.js';
import {isBreaklineBeforeProperty} from './calculate-long-assign-pattern.js';
import {printLeadingComments} from './comments.js';

@@ -14,4 +11,8 @@ import {shouldAddNewline} from './should-add-new-line.js';

} from './has.js';
import {isCommaAfterProperty} from './comma.js';
import {
isCommaAfterProperty,
isNewlineAfterComma,
} from './comma.js';
import {isIndentBeforeProperty} from './indent.js';
import {
isCoupleProperties,

@@ -55,6 +56,10 @@ isIndent,

for (const [i, property] of properties.entries()) {
const prevAssignObject = i && isPrevAssignObject(property);
if (isIndentBeforeProperty(property, {is}))
indent();
if (property.isRestElement()) {
const couple = is || hasObject;
maybe.indent(couple);
print(property);

@@ -65,3 +70,2 @@ maybe.print.newline(couple);

const prevAssignObject = i && isPrevAssignObject(property);
const nextAssignObject = isNextAssignObject(property);

@@ -80,7 +84,3 @@

maybe.indent((prevAssignObject || is) && notInsideFn);
maybe.print.breakline(couple && !isLongAssignPattern(property, semantics));
if (!isAssign && nextAssignObject)
if (isBreaklineBeforeProperty(property, {couple, semantics}))
print.breakline();

@@ -99,12 +99,13 @@

print(valuePath);
if (isCommaAfterProperty(property, {couple})) {
print(',');
print.newline();
continue;
}
}
if (isCommaAfterProperty(property, {is, couple}))
print(',');
if (isNewlineAfterComma(property, {couple})) {
print.newline();
continue;
}
if (!isAssign && nextAssignObject && notInsideFn) {
print(',');
print.breakline();

@@ -114,15 +115,9 @@ continue;

const {complexAssign} = calculateAssigns(property, semantics);
if (!complexAssign && (is || hasObject || prevAssignObject && notInsideFn)) {
print(',');
if (is || hasObject || prevAssignObject && notInsideFn) {
print.newline();
continue;
}
if (i < n && !(isAssign && couple)) {
print(',');
if (i < n && !(isAssign && couple))
print.space();
}
}

@@ -129,0 +124,0 @@

{
"name": "@putout/printer",
"version": "18.8.0",
"version": "18.8.1",
"type": "module",

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

Sorry, the diff of this file is not supported yet