@putout/printer 18.40.0 → 18.40.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,13 @@
1
+ 2026.08.22, v18.40.2
2
+
3
+ fix:
4
+ - 8134ac8f @putout/printer: json, sql
5
+
6
+ 2026.08.21, v18.40.1
7
+
8
+ feature:
9
+ - e137edf2 @putout/printer/ CallExpression: simplify
10
+
1
11
  2026.08.21, v18.40.0
2
12
 
3
13
  feature:
package/lib/printer.js CHANGED
@@ -7,12 +7,12 @@ export {maybeVisitor} from './tokenize/maybe/index.js';
7
7
  export * as visitors from './tokenize/visitors.js';
8
8
 
9
9
  export const print = (ast, overrides = {}) => {
10
+ let options = overrides;
10
11
  check(ast);
11
12
 
12
- const options = {
13
- ...maybeJSON(ast, overrides),
14
- ...maybeSQL(ast, overrides),
15
- };
13
+ for (const maybe of [maybeJSON, maybeSQL]) {
14
+ options = maybe(ast, options);
15
+ }
16
16
 
17
17
  const tokens = tokenize(ast, options);
18
18
 
@@ -1,8 +1,7 @@
1
1
  import {types} from '@putout/babel';
2
- import {exists, isInsideCall} from '#is';
2
+ import {isInsideCall} from '#is';
3
3
  import {maybeParens} from '#maybe-parens';
4
4
  import {createTypeChecker} from '#type-checker';
5
- import {CallExpressionWithMaxArgs} from './call-expression-with-max-args.js';
6
5
 
7
6
  const {
8
7
  isIdentifier,
@@ -21,62 +20,64 @@ const parseArgs = (path) => {
21
20
  return argsPath;
22
21
  };
23
22
 
24
- function isMaxArgs(path, {maxArgsInOneLine}) {
25
- const args = parseArgs(path);
26
-
27
- const [first] = args;
28
-
29
- if (isArrayExpression(first))
30
- return false;
31
-
32
- return args.length >= maxArgsInOneLine;
33
- }
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
+ ]);
34
30
 
35
- const isNeedsNewLine = createTypeChecker([
31
+ const isMultiline = createTypeChecker([
36
32
  ['-: -> !', tooLong],
37
33
  ['+', isInsideCall],
38
34
  ]);
39
35
 
40
36
  export const CallExpression = maybeParens((path, printer, semantics) => {
41
- if (isMaxArgs(path, semantics))
42
- return CallExpressionWithMaxArgs(path, printer);
43
-
44
- const {
45
- indent,
46
- print,
47
- maybe,
48
- traverse,
49
- } = printer;
37
+ const {print, maybe} = printer;
50
38
 
51
39
  const args = parseArgs(path);
52
- const needsNewline = isNeedsNewLine(path, semantics);
53
40
 
54
- const callee = path.get('callee');
55
- const typeParameters = path.get('typeArguments');
41
+ print('__callee');
42
+ print('__typeArguments');
43
+ maybe.print(path.node.optional, '?.');
56
44
 
57
- traverse(callee);
45
+ print('(');
58
46
 
59
- if (exists(typeParameters))
60
- traverse(typeParameters);
47
+ const maxArgs = isMaxArgs(path, semantics);
48
+ const multiline = maxArgs || isMultiline(path, semantics);
61
49
 
62
- if (path.node.optional)
63
- print('?.');
50
+ printArgs(args, printer, {
51
+ maxArgs,
52
+ multiline,
53
+ });
64
54
 
65
- print('(');
55
+ print(')');
56
+ });
57
+
58
+ export const OptionalCallExpression = CallExpression;
59
+
60
+ function printArgs(args, printer, {maxArgs, multiline}) {
61
+ const {
62
+ indent,
63
+ print,
64
+ maybe,
65
+ } = printer;
66
66
 
67
67
  const n = args.length - 1;
68
68
 
69
- maybe.indent.inc(needsNewline);
69
+ maybe.indent.inc(multiline);
70
70
 
71
71
  for (const [i, arg] of args.entries()) {
72
- const isObject = isObjectExpression(arg);
73
-
74
- if (needsNewline && !isObject && n)
75
- print.breakline();
72
+ if (multiline)
73
+ if (maxArgs && isArrayExpression(arg))
74
+ print.space();
75
+ else if (n || maxArgs && !isObjectExpression(arg))
76
+ print.breakline();
76
77
 
77
78
  print(arg);
78
79
 
79
- if (needsNewline && n) {
80
+ if (multiline && (n || maxArgs)) {
80
81
  print(',');
81
82
  continue;
82
83
  }
@@ -87,15 +88,11 @@ export const CallExpression = maybeParens((path, printer, semantics) => {
87
88
  }
88
89
  }
89
90
 
90
- if (needsNewline) {
91
+ if (multiline) {
91
92
  indent.dec();
92
- maybe.print.breakline(n);
93
+ maybe.print.breakline(n || maxArgs);
93
94
  }
94
-
95
- print(')');
96
- });
97
-
98
- export const OptionalCallExpression = CallExpression;
95
+ }
99
96
 
100
97
  function tooLong(path) {
101
98
  const args = parseArgs(path);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@putout/printer",
3
- "version": "18.40.0",
3
+ "version": "18.40.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",
@@ -79,6 +79,8 @@
79
79
  "@babel/parser": "^8.0.0",
80
80
  "@putout/eslint": "^6.0.0",
81
81
  "@putout/eslint-flat": "^4.0.0",
82
+ "@putout/operator-filesystem": "^11.2.1",
83
+ "@putout/operator-match-files": "^12.4.1",
82
84
  "@putout/plugin-minify": "^12.0.0",
83
85
  "@putout/plugin-printer": "^8.0.0",
84
86
  "@putout/plugin-promises": "^20.0.0",
@@ -1,27 +0,0 @@
1
- import {types} from '@putout/babel';
2
-
3
- const {isArrayExpression} = types;
4
-
5
- export const CallExpressionWithMaxArgs = (path, {write, indent, traverse}) => {
6
- const {name} = path.node.callee;
7
- const args = path.get('arguments');
8
-
9
- write(name);
10
- write('(');
11
- indent.inc();
12
-
13
- for (const arg of args) {
14
- if (isArrayExpression(arg))
15
- write.space();
16
- else
17
- write.breakline();
18
-
19
- traverse(arg);
20
- write(',');
21
- }
22
-
23
- indent.dec();
24
- write.breakline();
25
- write(')');
26
- };
27
-