@putout/printer 18.3.5 → 18.4.0

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,19 @@
1
+ 2026.03.10, v18.4.0
2
+
3
+ feature:
4
+ - 3bcdf4b @putout/printer: ObjectExpression: callWithCallee
5
+ - e205336 @putout/printer: ObjectExpression: isNewlineAfterProperty
6
+ - c4f998d @putout/printer: ObjectExpression: comma: simplify
7
+ - 2a49a3f @putout/printer: ObjectExpression: isLinebreakAfterProperty
8
+
9
+ 2026.03.10, v18.3.6
10
+
11
+ feature:
12
+ - a3281ef @putout/printer: ObjectExpression: isMultiline
13
+ - da64dc7 @putout/printer: ObjectExpression: isCommaAfterProperty
14
+ - 69ff480 @putout/printer: ObjectExpression: hasTrailingComment
15
+ - 50f7e07 @putout/printer: ObjectExpression: isIndentBeforeClosingCurlyBrace
16
+
1
17
  2026.03.10, v18.3.5
2
18
 
3
19
  feature:
@@ -0,0 +1,14 @@
1
+ import {createTypeChecker} from '#type-checker';
2
+ import {
3
+ isMultilineOption,
4
+ isTrailingCommaOption,
5
+ } from '../array-expression/is.js';
6
+
7
+ const isLastProperty = ({node, parentPath}) => node === parentPath.node.properties.at(-1);
8
+
9
+ export const isCommaAfterProperty = createTypeChecker([
10
+ ['-: -> !SpreadElement'],
11
+ ['-: -> !', isMultilineOption],
12
+ ['+: -> !', isLastProperty],
13
+ ['+', isTrailingCommaOption],
14
+ ]);
@@ -0,0 +1,12 @@
1
+ import {createTypeChecker} from '#type-checker';
2
+ import {
3
+ callWithNext,
4
+ hasLeadingComment,
5
+ isNewlineBetweenSiblings,
6
+ } from '#is';
7
+
8
+ export const isLinebreakAfterProperty = createTypeChecker([
9
+ ['-: -> SpreadElement'],
10
+ ['-', callWithNext(hasLeadingComment)],
11
+ ['+', isNewlineBetweenSiblings],
12
+ ]);
@@ -0,0 +1,12 @@
1
+ import {createTypeChecker} from '#type-checker';
2
+ import {
3
+ callWithNext,
4
+ hasLeadingComment,
5
+ } from '#is';
6
+ import {isMultilineOption} from '../array-expression/is.js';
7
+
8
+ export const isNewlineAfterProperty = createTypeChecker([
9
+ ['-: -> !', isMultilineOption],
10
+ ['+: -> SpreadElement'],
11
+ ['+: -> !', callWithNext(hasLeadingComment)],
12
+ ]);
@@ -4,17 +4,19 @@ import {
4
4
  isCoupleLines,
5
5
  isForOf,
6
6
  isIf,
7
- noTrailingComment,
8
- isNewlineBetweenSiblings,
9
7
  hasLeadingComment,
10
- exists,
11
8
  isInsideCall,
12
9
  isInsideBody,
13
10
  isInsideExpression,
11
+ hasTrailingComment,
14
12
  } from '#is';
15
13
  import {parseComments} from '../../comment/comment.js';
16
14
  import {isInsideTuple} from './is-inside-tuple.js';
17
15
  import {isLooksLikeChain} from '../member-expression/is-looks-like-chain.js';
16
+ import {isCommaAfterProperty} from './comma.js';
17
+ import {isMultilineOption} from '../array-expression/is.js';
18
+ import {isLinebreakAfterProperty} from './linebreak.js';
19
+ import {isNewlineAfterProperty} from './newline.js';
18
20
 
19
21
  const notLastArgInsideCall = (path) => {
20
22
  const {parentPath} = path;
@@ -35,12 +37,12 @@ const {isMemberExpression} = types;
35
37
 
36
38
  const isParens = createTypeChecker([isInsideBody, isInsideExpression]);
37
39
 
38
- const getCallee = (fn) => (a) => fn(a.get('callee'));
40
+ const callWithCallee = (fn) => (a) => fn(a.get('callee'));
39
41
 
40
42
  const isMemberExpressionCallee = createTypeChecker([
41
43
  ['-: parentPath -> !CallExpression'],
42
- ['-: parentPath -> !', getCallee(isMemberExpression)],
43
- ['+: parentPath', getCallee(isLooksLikeChain)],
44
+ ['-: parentPath -> !', callWithCallee(isMemberExpression)],
45
+ ['+: parentPath', callWithCallee(isLooksLikeChain)],
44
46
  ]);
45
47
 
46
48
  const isInsideNestedArrayCall = createTypeChecker([
@@ -55,7 +57,7 @@ const isInsideTupleLike = createTypeChecker([
55
57
  ['+: parentPath.parentPath.node.elements.0 -> StringLiteral'],
56
58
  ]);
57
59
 
58
- export const isManyLines = createTypeChecker([
60
+ export const isMultiline = createTypeChecker([
59
61
  ['-', hasNoProperties],
60
62
  ['-: parentPath -> ForOfStatement'],
61
63
  ['+: node.properties.0 -> SpreadElement'],
@@ -66,10 +68,8 @@ export const isManyLines = createTypeChecker([
66
68
  ['+', hasValue],
67
69
  ]);
68
70
 
69
- const isManyLinesOption = (a, {manyLines}) => manyLines;
70
-
71
71
  const isIndentBeforeProperty = createTypeChecker([
72
- ['-: -> !', isManyLinesOption],
72
+ ['-: -> !', isMultilineOption],
73
73
  ['+: -> !', hasLeadingComment],
74
74
  ]);
75
75
 
@@ -86,25 +86,20 @@ export const ObjectExpression = (path, printer, semantics) => {
86
86
  maybe.indent.inc(!insideNestedArrayCall);
87
87
 
88
88
  const properties = path.get('properties');
89
- const {length} = properties;
89
+
90
90
  const parens = isParens(path);
91
- const manyLines = isManyLines(path);
91
+ const multiline = isMultiline(path);
92
92
 
93
93
  maybe.print(parens, '(');
94
94
  print('{');
95
95
  parseComments(path, printer, semantics);
96
- maybe.print.newline(manyLines);
97
-
98
- const n = properties.length - 1;
96
+ maybe.print.newline(multiline);
99
97
 
100
98
  const memberCallee = isMemberExpressionCallee(path);
101
99
  maybe.indent.inc(memberCallee);
102
100
 
103
- for (const [index, property] of properties.entries()) {
104
- const couple = length > 1;
105
- const isLast = index === n;
106
-
107
- if (isIndentBeforeProperty(property, {manyLines}))
101
+ for (const property of properties) {
102
+ if (isIndentBeforeProperty(property, {multiline}))
108
103
  indent();
109
104
 
110
105
  print(property);
@@ -112,29 +107,28 @@ export const ObjectExpression = (path, printer, semantics) => {
112
107
  if (property.isObjectMethod())
113
108
  continue;
114
109
 
115
- if (property.isSpreadElement()) {
116
- if (noTrailingComment(property) && (couple || manyLines)) {
117
- maybe.print(!isLast || trailingComma, ',');
118
- print.newline();
119
- }
120
-
110
+ if (hasTrailingComment(property))
121
111
  continue;
122
- }
123
112
 
124
- if (noTrailingComment(property) && !hasNextLeadingComment(property)) {
125
- maybe.print.newline(manyLines);
126
- maybe.print.linebreak(isNewlineBetweenSiblings(property));
127
- }
113
+ maybe.print(isCommaAfterProperty(property, {
114
+ multiline,
115
+ trailingComma,
116
+ }), ',');
117
+
118
+ if (isNewlineAfterProperty(property, {multiline}))
119
+ print.newline();
120
+
121
+ if (isLinebreakAfterProperty(property))
122
+ print.linebreak();
128
123
  }
129
124
 
130
125
  indent.dec();
131
126
 
132
- if (!insideNestedArrayCall) {
133
- maybe.indent(manyLines);
134
- } else if (isInsideTupleLike(path)) {
127
+ if (isIndentBeforeClosingCurlyBrace(path, {multiline}))
135
128
  indent();
129
+
130
+ if (insideNestedArrayCall)
136
131
  indent.inc();
137
- }
138
132
 
139
133
  print('}');
140
134
  maybe.print(parens, ')');
@@ -142,11 +136,8 @@ export const ObjectExpression = (path, printer, semantics) => {
142
136
  maybe.indent.dec(memberCallee);
143
137
  };
144
138
 
145
- const hasNextLeadingComment = (path) => {
146
- const next = path.getNextSibling();
147
-
148
- if (!exists(next))
149
- return false;
150
-
151
- return hasLeadingComment(next);
152
- };
139
+ const isIndentBeforeClosingCurlyBrace = createTypeChecker([
140
+ ['+', isInsideTupleLike],
141
+ ['-: -> !', isMultilineOption],
142
+ ['+: -> !', isInsideNestedArrayCall],
143
+ ]);
@@ -1,5 +1,5 @@
1
1
  import {isConcatenation} from '../binary-expression/concatenate.js';
2
- import {isManyLines} from './object-expression.js';
2
+ import {isMultiline} from './object-expression.js';
3
3
  import {printKey} from './print-key.js';
4
4
 
5
5
  export const ObjectProperty = (path, printer, semantics) => {
@@ -14,7 +14,7 @@ export const ObjectProperty = (path, printer, semantics) => {
14
14
  const value = path.get('value');
15
15
  const properties = path.parentPath.get('properties');
16
16
  const isLast = path === properties.at(-1);
17
- const manyLines = isManyLines(path.parentPath);
17
+ const multiline = isMultiline(path.parentPath);
18
18
 
19
19
  printKey(path, printer);
20
20
 
@@ -24,7 +24,7 @@ export const ObjectProperty = (path, printer, semantics) => {
24
24
  traverse(value);
25
25
  }
26
26
 
27
- if (manyLines) {
27
+ if (multiline) {
28
28
  maybe.write(!isLast || trailingComma, ',');
29
29
  return;
30
30
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@putout/printer",
3
- "version": "18.3.5",
3
+ "version": "18.4.0",
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",