@putout/printer 18.47.1 → 18.47.3

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.3
2
+
3
+ feature:
4
+ - 8be3bb39 @putout/printer: CallExpression: isCommaAfterArg
5
+
6
+ 2026.10.03, v18.47.2
7
+
8
+ feature:
9
+ - c3133393 @putout/printer: CallExpression: isBreaklineAfterArg
10
+ - edd8d692 @putout/printer: CallExpression: apply type checker
11
+
1
12
  2026.10.01, v18.47.1
2
13
 
3
14
  feature:
@@ -3,9 +3,16 @@ import {isInsideCall} from '#is';
3
3
  import {maybeParens} from '#maybe-parens';
4
4
  import {createTypeChecker} from '#type-checker';
5
5
 
6
+ const getMaxArgsInOneLine = (path, {maxArgsInOneLine}) => maxArgsInOneLine;
7
+ const firstArgIsArray = (path) => isArrayExpression(path.node?.arguments?.[0]);
8
+
9
+ const isMaxArgs = createTypeChecker([
10
+ ['-', firstArgIsArray],
11
+ ['+: node.arguments.length', '>=', getMaxArgsInOneLine],
12
+ ]);
13
+
6
14
  const {
7
15
  isIdentifier,
8
- isObjectExpression,
9
16
  isArrayExpression,
10
17
  } = types;
11
18
 
@@ -20,14 +27,6 @@ const parseArgs = (path) => {
20
27
  return argsPath;
21
28
  };
22
29
 
23
- const getMaxArgsInOneLine = (path, {maxArgsInOneLine}) => maxArgsInOneLine;
24
- const firstArgIsArray = (path) => isArrayExpression(path.node?.arguments?.[0]);
25
-
26
- const isMaxArgs = createTypeChecker([
27
- ['-', firstArgIsArray],
28
- ['+: node.arguments.length', '>=', getMaxArgsInOneLine],
29
- ]);
30
-
31
30
  const isMemberCallee = createTypeChecker([
32
31
  '-: -> !CallExpression',
33
32
  '-: node.callee -> !MemberExpression',
@@ -45,28 +44,43 @@ const isMultiline = createTypeChecker([
45
44
  export const CallExpression = maybeParens((path, printer, semantics) => {
46
45
  const {print, maybe} = printer;
47
46
 
48
- const args = parseArgs(path);
49
-
50
47
  print('__callee');
51
48
  print('__typeArguments');
52
49
  maybe.print(path.node.optional, '?.');
53
50
 
54
51
  print('(');
55
52
 
56
- const maxArgs = isMaxArgs(path, semantics);
57
- const multiline = maxArgs || isMultiline(path, semantics);
58
-
59
- printArgs(args, printer, {
60
- maxArgs,
61
- multiline,
62
- });
53
+ printArgs(path, printer, semantics);
63
54
 
64
55
  print(')');
65
56
  });
66
57
 
67
58
  export const OptionalCallExpression = CallExpression;
68
59
 
69
- function printArgs(args, printer, {maxArgs, multiline}) {
60
+ const isSpaceAfterArg = createTypeChecker([
61
+ ['-: parentPath -> !', isMaxArgs],
62
+ ['+: -> ArrayExpression'],
63
+ ]);
64
+
65
+ const isBreaklineAfterArg = createTypeChecker([
66
+ ['-: -> ArrayExpression'],
67
+ ['+: parentPath', isMaxArgs],
68
+ ['+', isMemberCallee],
69
+ ['-: parentPath -> !', isMultiline],
70
+ ['+: parentPath.node.arguments.length', '>', 1],
71
+ ]);
72
+
73
+ const isCommaAfterArg = createTypeChecker([
74
+ ['+', isMaxArgs],
75
+ ['-: node.arguments.length', '<=', 1],
76
+ ['+', isMultiline],
77
+ ]);
78
+
79
+ function printArgs(path, printer, semantics) {
80
+ const args = parseArgs(path);
81
+ const maxArgs = isMaxArgs(path, semantics);
82
+ const multiline = maxArgs || isMultiline(path, semantics);
83
+
70
84
  const {
71
85
  indent,
72
86
  print,
@@ -78,15 +92,15 @@ function printArgs(args, printer, {maxArgs, multiline}) {
78
92
  maybe.indent.inc(multiline);
79
93
 
80
94
  for (const [i, arg] of args.entries()) {
81
- if (multiline)
82
- if (maxArgs && isArrayExpression(arg))
83
- print.space();
84
- else if (n || maxArgs && !isObjectExpression(arg) || isMemberCallee(arg))
85
- print.breakline();
95
+ if (isSpaceAfterArg(arg, semantics))
96
+ print.space();
97
+
98
+ if (isBreaklineAfterArg(arg, semantics))
99
+ print.breakline();
86
100
 
87
101
  print(arg);
88
102
 
89
- if (multiline && (n || maxArgs)) {
103
+ if (isCommaAfterArg(path, semantics)) {
90
104
  print(',');
91
105
  continue;
92
106
  }
@@ -114,3 +128,4 @@ function tooLong(path) {
114
128
 
115
129
  return false;
116
130
  }
131
+
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@putout/printer",
3
- "version": "18.47.1",
3
+ "version": "18.47.3",
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",