@putout/printer 18.47.1 → 18.47.2

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.2
2
+
3
+ feature:
4
+ - c3133393 @putout/printer: CallExpression: isBreaklineAfterArg
5
+ - edd8d692 @putout/printer: CallExpression: apply type checker
6
+
1
7
  2026.10.01, v18.47.1
2
8
 
3
9
  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,37 @@ 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
+ function printArgs(path, printer, semantics) {
74
+ const args = parseArgs(path);
75
+ const maxArgs = isMaxArgs(path, semantics);
76
+ const multiline = maxArgs || isMultiline(path, semantics);
77
+
70
78
  const {
71
79
  indent,
72
80
  print,
@@ -78,11 +86,11 @@ function printArgs(args, printer, {maxArgs, multiline}) {
78
86
  maybe.indent.inc(multiline);
79
87
 
80
88
  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();
89
+ if (isSpaceAfterArg(arg, semantics))
90
+ print.space();
91
+
92
+ if (isBreaklineAfterArg(arg, semantics))
93
+ print.breakline();
86
94
 
87
95
  print(arg);
88
96
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@putout/printer",
3
- "version": "18.47.1",
3
+ "version": "18.47.2",
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",