@putout/printer 18.8.0 → 18.8.1

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,12 @@
1
+ 2026.03.19, v18.8.1
2
+
3
+ feature:
4
+ - cbc16cf6 @putout/printer: ObjectPattern: isBreaklineBeforeProperty
5
+ - a78cf04e @putout/printer: ObjectPattern: isCommaAfterProperty
6
+ - c5b21af0 @putout/printer: ObjectPattern: simplify
7
+ - 394ff5e4 @putout/printer: ObjectPattern: calculateLongAssignPattern: simplify
8
+ - 42c8dfd4 @putout/printer: ObjectPattern: isIndentBeforeProperty
9
+
1
10
  2026.03.18, v18.8.0
2
11
 
3
12
  feature:
@@ -1,41 +1,20 @@
1
- import {types} from '@putout/babel';
1
+ import {createTypeChecker} from '#type-checker';
2
+ import {isNextAssignObject} from './is.js';
2
3
 
3
- const {
4
- isAssignmentPattern,
5
- isArrayExpression,
6
- isObjectExpression,
7
- isIdentifier,
8
- } = types;
9
-
10
- export const calculateAssigns = (property, semantics) => {
11
- const currentAssign = isLongAssignPattern(property, semantics);
12
-
13
- const {right} = property.node.value;
14
- const isArrayOrObjectRight = isArrayExpression(right) || isComplexObject(right);
15
- const complexAssign = currentAssign && isArrayOrObjectRight;
16
-
17
- return {
18
- complexAssign,
19
- };
4
+ const isMoreThenMaxPropertiesLengthInOneLineOption = (a, {semantics}) => {
5
+ const {maxPropertiesLengthInOneLine} = semantics;
6
+ return a > maxPropertiesLengthInOneLine;
20
7
  };
21
8
 
22
- export function isLongAssignPattern(path, semantics) {
23
- const {key, value} = path.node;
24
-
25
- if (!isAssignmentPattern(value))
26
- return false;
27
-
28
- if (!isIdentifier(key))
29
- return true;
30
-
31
- const {maxPropertiesLengthInOneLine} = semantics;
32
-
33
- return key.name.length > maxPropertiesLengthInOneLine;
34
- }
9
+ const isCoupleOption = (a, {couple}) => couple;
10
+
11
+ const isNextAssignAndCurrentNotAssign = createTypeChecker([
12
+ ['-: ->', isCoupleOption],
13
+ ['+: node.value -> AssignmentPattern'],
14
+ ['+: -> !', isNextAssignObject],
15
+ ]);
35
16
 
36
- function isComplexObject(node) {
37
- if (!isObjectExpression(node))
38
- return false;
39
-
40
- return node.properties.length;
41
- }
17
+ export const isBreaklineBeforeProperty = createTypeChecker([
18
+ ['-: ->', isNextAssignAndCurrentNotAssign],
19
+ ['+: node.key.name.length -> !', isMoreThenMaxPropertiesLengthInOneLineOption],
20
+ ]);
@@ -1,5 +1,11 @@
1
1
  import {types} from '@putout/babel';
2
2
  import {createTypeChecker} from '#type-checker';
3
+ import {callWithNext} from '#is';
4
+ import {
5
+ hasOptionIs,
6
+ isNextAssignObject,
7
+ isPrevAssignObject,
8
+ } from './is.js';
3
9
 
4
10
  const {
5
11
  isForOfStatement,
@@ -18,7 +24,21 @@ export function isPrevAssign(path) {
18
24
  return isAssignmentPattern(prev.node.value);
19
25
  }
20
26
 
27
+ const hasNode = (path) => path.node;
28
+
21
29
  export const isCommaAfterProperty = createTypeChecker([
30
+ ['+', isCoupleOption],
31
+ ['+', hasOptionIs],
32
+ ['+', isNextAssignObject],
33
+ ['+', isPrevAssignObject],
34
+ ['+', callWithNext(hasNode)],
35
+ ['-: key -> -'],
36
+ ['-', isPrevAssign],
37
+ ['-: parentPath', isInsideForOf],
38
+ ['+: node.value.right -> ObjectExpression'],
39
+ ]);
40
+
41
+ export const isNewlineAfterComma = createTypeChecker([
22
42
  ['+', isCoupleOption],
23
43
  ['-: key -> -'],
24
44
  ['-', isPrevAssign],
@@ -0,0 +1,12 @@
1
+ import {createTypeChecker} from '#type-checker';
2
+ import {
3
+ hasOptionIs,
4
+ isInsideFn,
5
+ isPrevAssignObject,
6
+ } from './is.js';
7
+
8
+ export const isIndentBeforeProperty = createTypeChecker([
9
+ ['-', isInsideFn],
10
+ ['+', isPrevAssignObject],
11
+ ['+', hasOptionIs],
12
+ ]);
@@ -14,6 +14,8 @@ const {
14
14
  isObjectProperty,
15
15
  } = types;
16
16
 
17
+ export const hasOptionIs = (a, {is}) => is;
18
+
17
19
  export const isInsideFn = (path) => {
18
20
  if (isFunction(path.parentPath))
19
21
  return true;
@@ -46,4 +48,8 @@ export const isPrevAssignObject = callWithPrev(createTypeChecker([
46
48
  '+: node.value.right -> ObjectExpression',
47
49
  ]));
48
50
 
49
- export const isNextAssignObject = callWithNext(createTypeChecker(['-: node -> -', '-: node.value -> !AssignmentPattern', '+: node.value.right -> ObjectExpression']));
51
+ export const isNextAssignObject = callWithNext(createTypeChecker([
52
+ '-: node -> -',
53
+ '-: node.value -> !AssignmentPattern',
54
+ '+: node.value.right -> ObjectExpression',
55
+ ]));
@@ -1,17 +1,18 @@
1
1
  import {wrongShorthand} from './wrong-shorthand.js';
2
2
  import {maybeTypeAnnotation} from '../../maybe/maybe-type-annotation.js';
3
3
  import {printKey} from '../object-expression/print-key.js';
4
- import {
5
- calculateAssigns,
6
- isLongAssignPattern,
7
- } from './calculate-long-assign-pattern.js';
4
+ import {isBreaklineBeforeProperty} from './calculate-long-assign-pattern.js';
8
5
  import {printLeadingComments} from './comments.js';
9
6
  import {shouldAddNewline} from './should-add-new-line.js';
10
7
  import {
11
8
  hasAssignObject,
12
9
  hasObjectPattern,
13
10
  } from './has.js';
14
- import {isCommaAfterProperty} from './comma.js';
11
+ import {
12
+ isCommaAfterProperty,
13
+ isNewlineAfterComma,
14
+ } from './comma.js';
15
+ import {isIndentBeforeProperty} from './indent.js';
15
16
  import {
16
17
  isCoupleProperties,
17
18
  isIndent,
@@ -51,16 +52,19 @@ export const ObjectPattern = {
51
52
  maybe.print.newline(is && notInsideFn);
52
53
 
53
54
  for (const [i, property] of properties.entries()) {
55
+ const prevAssignObject = i && isPrevAssignObject(property);
56
+
57
+ if (isIndentBeforeProperty(property, {is}))
58
+ indent();
59
+
54
60
  if (property.isRestElement()) {
55
61
  const couple = is || hasObject;
56
62
 
57
- maybe.indent(couple);
58
63
  print(property);
59
64
  maybe.print.newline(couple);
60
65
  continue;
61
66
  }
62
67
 
63
- const prevAssignObject = i && isPrevAssignObject(property);
64
68
  const nextAssignObject = isNextAssignObject(property);
65
69
 
66
70
  const valuePath = property.get('value');
@@ -74,11 +78,7 @@ export const ObjectPattern = {
74
78
  valuePath,
75
79
  });
76
80
 
77
- maybe.indent((prevAssignObject || is) && notInsideFn);
78
-
79
- maybe.print.breakline(couple && !isLongAssignPattern(property, semantics));
80
-
81
- if (!isAssign && nextAssignObject)
81
+ if (isBreaklineBeforeProperty(property, {couple, semantics}))
82
82
  print.breakline();
83
83
 
84
84
  printLeadingComments(property, {
@@ -92,33 +92,28 @@ export const ObjectPattern = {
92
92
  print(valuePath);
93
93
  } else if (isAssign) {
94
94
  print(valuePath);
95
-
96
- if (isCommaAfterProperty(property, {couple})) {
97
- print(',');
98
- print.newline();
99
- continue;
100
- }
101
95
  }
102
96
 
103
- if (!isAssign && nextAssignObject && notInsideFn) {
97
+ if (isCommaAfterProperty(property, {is, couple}))
104
98
  print(',');
105
- print.breakline();
99
+
100
+ if (isNewlineAfterComma(property, {couple})) {
101
+ print.newline();
106
102
  continue;
107
103
  }
108
104
 
109
- const {complexAssign} = calculateAssigns(property, semantics);
105
+ if (!isAssign && nextAssignObject && notInsideFn) {
106
+ print.breakline();
107
+ continue;
108
+ }
110
109
 
111
- if (!complexAssign && (is || hasObject || prevAssignObject && notInsideFn)) {
112
- print(',');
110
+ if (is || hasObject || prevAssignObject && notInsideFn) {
113
111
  print.newline();
114
-
115
112
  continue;
116
113
  }
117
114
 
118
- if (i < n && !(isAssign && couple)) {
119
- print(',');
115
+ if (i < n && !(isAssign && couple))
120
116
  print.space();
121
- }
122
117
  }
123
118
 
124
119
  indent.dec();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@putout/printer",
3
- "version": "18.8.0",
3
+ "version": "18.8.1",
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",