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