@putout/printer 18.8.0 → 18.8.2

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,18 @@
1
+ 2026.03.19, v18.8.2
2
+
3
+ feature:
4
+ - 62e8f395 @putout/printer: ObjectPattern: isIndentAfterNewline
5
+ - 03b337f7 @putout/printer: ObjectPattern: isNewlineAfterComma: simplify
6
+
7
+ 2026.03.19, v18.8.1
8
+
9
+ feature:
10
+ - cbc16cf6 @putout/printer: ObjectPattern: isBreaklineBeforeProperty
11
+ - a78cf04e @putout/printer: ObjectPattern: isCommaAfterProperty
12
+ - c5b21af0 @putout/printer: ObjectPattern: simplify
13
+ - 394ff5e4 @putout/printer: ObjectPattern: calculateLongAssignPattern: simplify
14
+ - 42c8dfd4 @putout/printer: ObjectPattern: isIndentBeforeProperty
15
+
1
16
  2026.03.18, v18.8.0
2
17
 
3
18
  feature:
@@ -59,7 +59,8 @@ export const printLeadingComments = (path, printer, semantics, {currentTraverse}
59
59
  export const printTrailingComments = (path, printer, semantics, {currentTraverse}) => {
60
60
  const {print} = printer;
61
61
  const {
62
- trailingComments = []} = path.node;
62
+ trailingComments = [],
63
+ } = path.node;
63
64
 
64
65
  const {
65
66
  printTrailingCommentLine,
@@ -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,10 +24,25 @@ 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([
22
30
  ['+', isCoupleOption],
31
+ ['+', hasOptionIs],
32
+ ['+', isNextAssignObject],
33
+ ['+', isPrevAssignObject],
34
+ ['+', callWithNext(hasNode)],
23
35
  ['-: key -> -'],
24
36
  ['-', isPrevAssign],
25
37
  ['-: parentPath', isInsideForOf],
26
38
  ['+: node.value.right -> ObjectExpression'],
27
39
  ]);
40
+
41
+ export const isNewlineAfterComma = createTypeChecker([
42
+ ['+', hasOptionIs],
43
+ ['+', isPrevAssignObject],
44
+ ['+', isCoupleOption],
45
+ ['+', isNextAssignObject],
46
+ ['-: key -> -'],
47
+ ['+: node.value.right -> ObjectExpression'],
48
+ ]);
@@ -0,0 +1,18 @@
1
+ import {createTypeChecker} from '#type-checker';
2
+ import {
3
+ hasOptionIs,
4
+ isInsideFn,
5
+ isNextAssignObject,
6
+ isPrevAssignObject,
7
+ } from './is.js';
8
+
9
+ export const isIndentBeforeProperty = createTypeChecker([
10
+ ['-', isInsideFn],
11
+ ['+', isPrevAssignObject],
12
+ ['+', hasOptionIs],
13
+ ]);
14
+
15
+ export const isIndentAfterNewline = createTypeChecker([
16
+ ['-: node.value -> AssignmentPattern'],
17
+ ['+', isNextAssignObject],
18
+ ]);
@@ -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,23 +1,25 @@
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 {
16
+ isIndentBeforeProperty,
17
+ isIndentAfterNewline,
18
+ } from './indent.js';
15
19
  import {
16
20
  isCoupleProperties,
17
21
  isIndent,
18
22
  isInsideFn,
19
- isNextAssignObject,
20
- isPrevAssignObject,
21
23
  } from './is.js';
22
24
 
23
25
  export const ObjectPattern = {
@@ -51,18 +53,17 @@ export const ObjectPattern = {
51
53
  maybe.print.newline(is && notInsideFn);
52
54
 
53
55
  for (const [i, property] of properties.entries()) {
56
+ if (isIndentBeforeProperty(property, {is}))
57
+ indent();
58
+
54
59
  if (property.isRestElement()) {
55
60
  const couple = is || hasObject;
56
61
 
57
- maybe.indent(couple);
58
62
  print(property);
59
63
  maybe.print.newline(couple);
60
64
  continue;
61
65
  }
62
66
 
63
- const prevAssignObject = i && isPrevAssignObject(property);
64
- const nextAssignObject = isNextAssignObject(property);
65
-
66
67
  const valuePath = property.get('value');
67
68
  const keyPath = property.get('key');
68
69
  const isAssign = valuePath.isAssignmentPattern();
@@ -74,11 +75,7 @@ export const ObjectPattern = {
74
75
  valuePath,
75
76
  });
76
77
 
77
- maybe.indent((prevAssignObject || is) && notInsideFn);
78
-
79
- maybe.print.breakline(couple && !isLongAssignPattern(property, semantics));
80
-
81
- if (!isAssign && nextAssignObject)
78
+ if (isBreaklineBeforeProperty(property, {couple, semantics}))
82
79
  print.breakline();
83
80
 
84
81
  printLeadingComments(property, {
@@ -92,33 +89,22 @@ export const ObjectPattern = {
92
89
  print(valuePath);
93
90
  } else if (isAssign) {
94
91
  print(valuePath);
95
-
96
- if (isCommaAfterProperty(property, {couple})) {
97
- print(',');
98
- print.newline();
99
- continue;
100
- }
101
92
  }
102
93
 
103
- if (!isAssign && nextAssignObject && notInsideFn) {
94
+ if (isCommaAfterProperty(property, {is, couple}))
104
95
  print(',');
105
- print.breakline();
106
- continue;
107
- }
108
-
109
- const {complexAssign} = calculateAssigns(property, semantics);
110
96
 
111
- if (!complexAssign && (is || hasObject || prevAssignObject && notInsideFn)) {
112
- print(',');
97
+ if (isNewlineAfterComma(property, {is, couple})) {
113
98
  print.newline();
114
99
 
100
+ if (isIndentAfterNewline(property))
101
+ indent();
102
+
115
103
  continue;
116
104
  }
117
105
 
118
- if (i < n && !(isAssign && couple)) {
119
- print(',');
106
+ if (i < n)
120
107
  print.space();
121
- }
122
108
  }
123
109
 
124
110
  indent.dec();
@@ -42,7 +42,12 @@ export const report = (coverage) => {
42
42
  };
43
43
 
44
44
  const setLine = (name, index) => {
45
- const [at, uri, line, column] = name.split(':');
45
+ const [
46
+ at,
47
+ uri,
48
+ line,
49
+ column,
50
+ ] = name.split(':');
46
51
  const newLine = Number(line) + index + 1;
47
52
 
48
53
  return [
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@putout/printer",
3
- "version": "18.8.0",
3
+ "version": "18.8.2",
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",