@putout/printer 18.3.6 → 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,11 @@
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
+
1
9
  2026.03.10, v18.3.6
2
10
 
3
11
  feature:
@@ -4,21 +4,11 @@ import {
4
4
  isTrailingCommaOption,
5
5
  } from '../array-expression/is.js';
6
6
 
7
- const isCouple = (a) => a > 1;
8
7
  const isLastProperty = ({node, parentPath}) => node === parentPath.node.properties.at(-1);
9
8
 
10
- const isCoupleOrManyLines = createTypeChecker([
11
- ['+: parentPath.node.properties.length ->', isCouple],
12
- ['+', isMultilineOption],
13
- ]);
14
-
15
- const isLastOrTrailingComma = createTypeChecker([
16
- ['+: -> !', isLastProperty],
17
- ['+', isTrailingCommaOption],
18
- ]);
19
-
20
9
  export const isCommaAfterProperty = createTypeChecker([
21
10
  ['-: -> !SpreadElement'],
22
- ['-: -> !', isCoupleOrManyLines],
23
- ['+', isLastOrTrailingComma],
11
+ ['-: -> !', isMultilineOption],
12
+ ['+: -> !', isLastProperty],
13
+ ['+', isTrailingCommaOption],
24
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,12 +4,10 @@ import {
4
4
  isCoupleLines,
5
5
  isForOf,
6
6
  isIf,
7
- isNewlineBetweenSiblings,
8
7
  hasLeadingComment,
9
8
  isInsideCall,
10
9
  isInsideBody,
11
10
  isInsideExpression,
12
- callWithNext,
13
11
  hasTrailingComment,
14
12
  } from '#is';
15
13
  import {parseComments} from '../../comment/comment.js';
@@ -17,8 +15,8 @@ import {isInsideTuple} from './is-inside-tuple.js';
17
15
  import {isLooksLikeChain} from '../member-expression/is-looks-like-chain.js';
18
16
  import {isCommaAfterProperty} from './comma.js';
19
17
  import {isMultilineOption} from '../array-expression/is.js';
20
-
21
- const hasNextLeadingComment = callWithNext(hasLeadingComment);
18
+ import {isLinebreakAfterProperty} from './linebreak.js';
19
+ import {isNewlineAfterProperty} from './newline.js';
22
20
 
23
21
  const notLastArgInsideCall = (path) => {
24
22
  const {parentPath} = path;
@@ -35,19 +33,16 @@ const notLastArgInsideCall = (path) => {
35
33
  const hasNoProperties = (path) => !path.node.properties.length;
36
34
  const hasValue = (path) => path.node.properties[0].value;
37
35
 
38
- const {
39
- isMemberExpression,
40
- isSpreadElement,
41
- } = types;
36
+ const {isMemberExpression} = types;
42
37
 
43
38
  const isParens = createTypeChecker([isInsideBody, isInsideExpression]);
44
39
 
45
- const getCallee = (fn) => (a) => fn(a.get('callee'));
40
+ const callWithCallee = (fn) => (a) => fn(a.get('callee'));
46
41
 
47
42
  const isMemberExpressionCallee = createTypeChecker([
48
43
  ['-: parentPath -> !CallExpression'],
49
- ['-: parentPath -> !', getCallee(isMemberExpression)],
50
- ['+: parentPath', getCallee(isLooksLikeChain)],
44
+ ['-: parentPath -> !', callWithCallee(isMemberExpression)],
45
+ ['+: parentPath', callWithCallee(isLooksLikeChain)],
51
46
  ]);
52
47
 
53
48
  const isInsideNestedArrayCall = createTypeChecker([
@@ -91,7 +86,7 @@ export const ObjectExpression = (path, printer, semantics) => {
91
86
  maybe.indent.inc(!insideNestedArrayCall);
92
87
 
93
88
  const properties = path.get('properties');
94
- const {length} = properties;
89
+
95
90
  const parens = isParens(path);
96
91
  const multiline = isMultiline(path);
97
92
 
@@ -104,8 +99,6 @@ export const ObjectExpression = (path, printer, semantics) => {
104
99
  maybe.indent.inc(memberCallee);
105
100
 
106
101
  for (const property of properties) {
107
- const couple = length > 1;
108
-
109
102
  if (isIndentBeforeProperty(property, {multiline}))
110
103
  indent();
111
104
 
@@ -122,10 +115,10 @@ export const ObjectExpression = (path, printer, semantics) => {
122
115
  trailingComma,
123
116
  }), ',');
124
117
 
125
- if (!isSpreadElement(property) && !hasNextLeadingComment(property) && multiline || property.isSpreadElement() && (couple || multiline))
118
+ if (isNewlineAfterProperty(property, {multiline}))
126
119
  print.newline();
127
120
 
128
- if (!isSpreadElement(property) && !hasNextLeadingComment(property) && isNewlineBetweenSiblings(property))
121
+ if (isLinebreakAfterProperty(property))
129
122
  print.linebreak();
130
123
  }
131
124
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@putout/printer",
3
- "version": "18.3.6",
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",