@putout/printer 18.8.3 → 18.8.4

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,8 @@
1
+ 2026.03.20, v18.8.4
2
+
3
+ feature:
4
+ - 292d01c0 @putout/printer: ObjectPattern: simplify
5
+
1
6
  2026.03.20, v18.8.3
2
7
 
3
8
  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,16 @@
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
+
11
12
  const isMoreCountLessLength = createTypeChecker([
12
- ['-: -> !', isLessThenMaxPropertiesInOneLine],
13
+ ['-: node.properties.length', '>', getMaxPropertiesInOneLine],
13
14
  ['-', isMoreThenMaxPropertiesLengthInOneLine],
14
15
  ['+: parentPath -> VariableDeclarator'],
15
16
  ]);
@@ -104,3 +105,4 @@ function hasComputed(path) {
104
105
 
105
106
  return false;
106
107
  }
108
+
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@putout/printer",
3
- "version": "18.8.3",
3
+ "version": "18.8.4",
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
- ]);