@putout/printer 18.8.3 → 18.8.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/ChangeLog CHANGED
@@ -1,3 +1,13 @@
1
+ 2026.03.20, v18.8.5
2
+
3
+ feature:
4
+ - a9df5bc7 @putout/printer: ObjectPattern: shouldAddNewline: simplify
5
+
6
+ 2026.03.20, v18.8.4
7
+
8
+ feature:
9
+ - 292d01c0 @putout/printer: ObjectPattern: simplify
10
+
1
11
  2026.03.20, v18.8.3
2
12
 
3
13
  feature:
@@ -1,9 +1,9 @@
1
1
  import {types} from '@putout/babel';
2
+ import {isAssignObject} from './is.js';
2
3
 
3
4
  const {
4
5
  isAssignmentPattern,
5
6
  isObjectPattern,
6
- isObjectExpression,
7
7
  } = types;
8
8
 
9
9
  export function hasObjectPattern(path) {
@@ -24,15 +24,13 @@ export function hasAssign(path) {
24
24
  return false;
25
25
  }
26
26
 
27
- export function hasAssignObject(path, maxPropertiesLengthInOneLine) {
27
+ export function hasAssignObject(path) {
28
28
  const properties = path.get('properties');
29
29
  const n = properties.length;
30
30
 
31
31
  for (const prop of properties) {
32
- const {value} = prop.node;
33
-
34
- if (isAssignmentPattern(value) && isObjectExpression(value.right))
35
- return n > 1 || maxPropertiesLengthInOneLine <= value.left;
32
+ if (isAssignObject(prop))
33
+ return n > 1;
36
34
  }
37
35
 
38
36
  return false;
@@ -25,13 +25,12 @@ export const isMoreThenMaxPropertiesLengthInOneLine = (path, {maxPropertiesLengt
25
25
  return true;
26
26
  }
27
27
 
28
- if (!isIdentifier(key))
29
- continue;
30
-
31
- const {name} = key;
32
-
33
- if (name.length >= maxPropertiesLengthInOneLine)
34
- return true;
28
+ if (isIdentifier(key)) {
29
+ const {name} = key;
30
+
31
+ if (name.length >= maxPropertiesLengthInOneLine)
32
+ return true;
33
+ }
35
34
  }
36
35
 
37
36
  return false;
@@ -42,13 +42,10 @@ export const isCoupleProperties = ({path, valuePath, property}) => {
42
42
  return !isObjectProperty(parentPath);
43
43
  };
44
44
 
45
- export const isPrevAssignObject = callWithPrev(createTypeChecker([
45
+ export const isAssignObject = createTypeChecker([
46
46
  '-: node.value -> !AssignmentPattern',
47
47
  '+: node.value.right -> ObjectExpression',
48
- ]));
48
+ ]);
49
49
 
50
- export const isNextAssignObject = callWithNext(createTypeChecker([
51
- '-: node -> -',
52
- '-: node.value -> !AssignmentPattern',
53
- '+: node.value.right -> ObjectExpression',
54
- ]));
50
+ export const isPrevAssignObject = callWithPrev(isAssignObject);
51
+ export const isNextAssignObject = callWithNext(isAssignObject);
@@ -109,7 +109,7 @@ export const ObjectPattern = {
109
109
 
110
110
  indent.dec();
111
111
 
112
- maybe.indent(is || hasAssignObject(path, maxPropertiesLengthInOneLine));
112
+ maybe.indent(is || hasAssignObject(path));
113
113
  maybe.indent.inc(!shouldIndent);
114
114
  print('}');
115
115
  }),
@@ -1,15 +1,17 @@
1
1
  import {types} from '@putout/babel';
2
2
  import {callWithParent, isForOf} from '#is';
3
3
  import {createTypeChecker} from '#type-checker';
4
- import {isLessThenMaxPropertiesInOneLine} from './is-less-then-max-properties-in-one-line.js';
5
4
  import {isMoreThenMaxPropertiesLengthInOneLine} from './is-more-then-max-properties-length-in-one-line.js';
6
5
  import {
7
6
  hasAssign,
8
7
  hasObjectPattern,
9
8
  } from './has.js';
10
9
 
10
+ const getMaxPropertiesInOneLine = (a, {maxPropertiesInOneLine}) => maxPropertiesInOneLine;
11
+ const getValue = (a) => a.value;
12
+
11
13
  const isMoreCountLessLength = createTypeChecker([
12
- ['-: -> !', isLessThenMaxPropertiesInOneLine],
14
+ ['-: node.properties.length', '>', getMaxPropertiesInOneLine],
13
15
  ['-', isMoreThenMaxPropertiesLengthInOneLine],
14
16
  ['+: parentPath -> VariableDeclarator'],
15
17
  ]);
@@ -66,21 +68,14 @@ function isCoupleAssigns(path) {
66
68
  if (isFunctionParam(path))
67
69
  return false;
68
70
 
69
- let assignsCount = 0;
70
-
71
- for (const property of path.node.properties) {
72
- if (!isObjectProperty(property))
73
- continue;
74
-
75
- if (isAssignmentPattern(property.value))
76
- ++assignsCount;
77
- }
71
+ const properties = path.node.properties
72
+ .filter(isObjectProperty)
73
+ .map(getValue)
74
+ .filter(isAssignmentPattern);
78
75
 
79
- return assignsCount > 1;
76
+ return properties.length > 1;
80
77
  }
81
78
 
82
- const getValue = (a) => a.value;
83
-
84
79
  function checkLength(path) {
85
80
  const identifiers = path
86
81
  .node
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@putout/printer",
3
- "version": "18.8.3",
3
+ "version": "18.8.5",
4
4
  "type": "module",
5
5
  "author": "coderaiser <mnemonic.enemy@gmail.com> (https://github.com/coderaiser)",
6
6
  "description": "Simplest possible opinionated Babel AST printer for 🐊Putout",
@@ -1,7 +0,0 @@
1
- import {createTypeChecker} from '#type-checker';
2
-
3
- const getMaxPropertiesInOneLine = (a, {maxPropertiesInOneLine}) => maxPropertiesInOneLine;
4
-
5
- export const isLessThenMaxPropertiesInOneLine = createTypeChecker([
6
- ['+: node.properties.length', '<=', getMaxPropertiesInOneLine],
7
- ]);