@putout/printer 18.47.2 → 18.47.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,14 @@
1
+ 2026.10.03, v18.47.4
2
+
3
+ feature:
4
+ - 4b751ba4 @putout/printer: CallExpression: isCommaAfterArg: merge
5
+ - df951f4f @putout/printer: CallExpression: isBreaklineAfterAllArgs
6
+
7
+ 2026.10.03, v18.47.3
8
+
9
+ feature:
10
+ - 8be3bb39 @putout/printer: CallExpression: isCommaAfterArg
11
+
1
12
  2026.10.03, v18.47.2
2
13
 
3
14
  feature:
@@ -3,6 +3,15 @@ import {isInsideCall} from '#is';
3
3
  import {maybeParens} from '#maybe-parens';
4
4
  import {createTypeChecker} from '#type-checker';
5
5
 
6
+ const isLast = (arg) => {
7
+ const {length} = arg.parentPath.node.arguments;
8
+ const n = length - 1;
9
+
10
+ return arg.key === n;
11
+ };
12
+
13
+ const getFirstArg = (fn) => (path) => fn(path.get('arguments.0'));
14
+
6
15
  const getMaxArgsInOneLine = (path, {maxArgsInOneLine}) => maxArgsInOneLine;
7
16
  const firstArgIsArray = (path) => isArrayExpression(path.node?.arguments?.[0]);
8
17
 
@@ -70,22 +79,31 @@ const isBreaklineAfterArg = createTypeChecker([
70
79
  ['+: parentPath.node.arguments.length', '>', 1],
71
80
  ]);
72
81
 
82
+ const isCommaAfterArg = createTypeChecker([
83
+ ['+: -> !', isLast],
84
+ ['+', isMemberCallee],
85
+ ['+: parentPath', isMaxArgs],
86
+ ['-: parentPath.node.arguments.length', '<=', 1],
87
+ ['+: parentPath', isMultiline],
88
+ ]);
89
+
90
+ const isBreaklineAfterAllArgs = createTypeChecker([
91
+ ['+', isMaxArgs],
92
+ ['-: -> !', isMultiline],
93
+ ['+: node.arguments.length', '>', 1],
94
+ ['+', getFirstArg(isMemberCallee)],
95
+ ]);
96
+
97
+ const isIndent = createTypeChecker([isMaxArgs, isMultiline]);
98
+
73
99
  function printArgs(path, printer, semantics) {
100
+ const {indent, print} = printer;
74
101
  const args = parseArgs(path);
75
- const maxArgs = isMaxArgs(path, semantics);
76
- const multiline = maxArgs || isMultiline(path, semantics);
77
-
78
- const {
79
- indent,
80
- print,
81
- maybe,
82
- } = printer;
83
-
84
- const n = args.length - 1;
85
102
 
86
- maybe.indent.inc(multiline);
103
+ if (isIndent(path, semantics))
104
+ indent.inc();
87
105
 
88
- for (const [i, arg] of args.entries()) {
106
+ for (const arg of args) {
89
107
  if (isSpaceAfterArg(arg, semantics))
90
108
  print.space();
91
109
 
@@ -94,24 +112,26 @@ function printArgs(path, printer, semantics) {
94
112
 
95
113
  print(arg);
96
114
 
97
- if (multiline && (n || maxArgs)) {
98
- print(',');
99
- continue;
100
- }
101
-
102
- if (isMemberCallee(arg) || i < n)
115
+ if (isCommaAfterArg(arg, semantics))
103
116
  print(',');
104
117
 
105
- if (i < n)
118
+ if (isSpace(arg, semantics))
106
119
  print.space();
107
120
  }
108
121
 
109
- if (multiline) {
122
+ if (isIndent(path, semantics))
110
123
  indent.dec();
111
- maybe.print.breakline(n || maxArgs || isMemberCallee(args[0]));
112
- }
124
+
125
+ if (isBreaklineAfterAllArgs(path, semantics))
126
+ print.breakline();
113
127
  }
114
128
 
129
+ const isSpace = createTypeChecker([
130
+ ['-: parentPath', isMultiline],
131
+ ['-: parentPath', isMaxArgs],
132
+ ['+: -> !', isLast],
133
+ ]);
134
+
115
135
  function tooLong(path) {
116
136
  const args = parseArgs(path);
117
137
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@putout/printer",
3
- "version": "18.47.2",
3
+ "version": "18.47.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",