@putout/printer 18.43.0 → 18.44.0

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,8 @@
1
+ 2026.09.10, v18.44.0
2
+
3
+ feature:
4
+ - 6428169a @putout/printer: CallExpression: with first argument chainend call expression: new lines
5
+
1
6
  2026.09.07, v18.43.0
2
7
 
3
8
  feature:
package/lib/printer.d.ts CHANGED
@@ -19,8 +19,11 @@ export interface Semantics {
19
19
  }
20
20
 
21
21
  export type PrinterPrint = (input: string | Node) => void;
22
+
22
23
  export type Indent = () => void;
24
+
23
25
  export type Traverse = (input: Node) => void;
26
+
24
27
  export type MaybeCondition = (condition: boolean) => void;
25
28
 
26
29
  export type MaybeIndent = {
@@ -59,6 +62,7 @@ export interface Options {
59
62
  }
60
63
 
61
64
  type Print = (ast: Node, options?: Options) => string;
65
+
62
66
  export const print: Print;
63
67
 
64
68
  export declare function maybeVisitor(plugin: Visitor, path: Node, printer: Printer, semantics: Semantics): void;
@@ -28,7 +28,16 @@ const isMaxArgs = createTypeChecker([
28
28
  ['+: node.arguments.length', '>=', getMaxArgsInOneLine],
29
29
  ]);
30
30
 
31
+ const isMemberCallee = createTypeChecker([
32
+ '-: -> !CallExpression',
33
+ '-: node.callee -> !MemberExpression',
34
+ '+: node.callee.object -> CallExpression',
35
+ ]);
36
+
37
+ const callWithArg = (fn) => (path) => fn(path.get('arguments')[0]);
38
+
31
39
  const isMultiline = createTypeChecker([
40
+ ['+', callWithArg(isMemberCallee)],
32
41
  ['-: -> !', tooLong],
33
42
  ['+', isInsideCall],
34
43
  ]);
@@ -72,7 +81,7 @@ function printArgs(args, printer, {maxArgs, multiline}) {
72
81
  if (multiline)
73
82
  if (maxArgs && isArrayExpression(arg))
74
83
  print.space();
75
- else if (n || maxArgs && !isObjectExpression(arg))
84
+ else if (n || maxArgs && !isObjectExpression(arg) || isMemberCallee(arg))
76
85
  print.breakline();
77
86
 
78
87
  print(arg);
@@ -82,15 +91,16 @@ function printArgs(args, printer, {maxArgs, multiline}) {
82
91
  continue;
83
92
  }
84
93
 
85
- if (i < n) {
94
+ if (isMemberCallee(arg) || i < n)
86
95
  print(',');
96
+
97
+ if (i < n)
87
98
  print.space();
88
- }
89
99
  }
90
100
 
91
101
  if (multiline) {
92
102
  indent.dec();
93
- maybe.print.breakline(n || maxArgs);
103
+ maybe.print.breakline(n || maxArgs || isMemberCallee(args[0]));
94
104
  }
95
105
  }
96
106
 
@@ -21,4 +21,3 @@ export const printConditionalExpressionMultiline = (path, {print, indent}) => {
21
21
  indent.dec();
22
22
  print('__alternate');
23
23
  };
24
-
@@ -4,6 +4,8 @@ export {Decorator} from './decorator/decorator.js';
4
4
  export {StringLiteral} from './string-literal.js';
5
5
  export {DirectiveLiteral} from './directive-literal.js';
6
6
  export {VoidPattern} from './void-pattern/void-pattern.js';
7
+ export {RegExpLiteral} from './regexp-literal/regexp-literal.js';
8
+
7
9
  export const BigIntLiteral = (path, {write}) => {
8
10
  write(path.node.raw);
9
11
  };
@@ -27,11 +29,6 @@ export const BooleanLiteral = (path, {write}) => {
27
29
  write(path.node.value);
28
30
  };
29
31
 
30
- export const RegExpLiteral = (path, {print}) => {
31
- const {raw, pattern} = path.node;
32
- print(raw || `/${pattern}/`);
33
- };
34
-
35
32
  export const NullLiteral = (path, {write}) => {
36
33
  write('null');
37
34
  };
@@ -0,0 +1,4 @@
1
+ export const RegExpLiteral = (path, {print}) => {
2
+ const {raw, pattern} = path.node;
3
+ print(raw || `/${pattern}/`);
4
+ };
@@ -25,9 +25,11 @@ export const maybeThrow = (a, path, b) => {
25
25
 
26
26
  const maybeStatement = (ast) => isStatement(ast) ? ast : expressionStatement(ast);
27
27
 
28
- const maybeProgram = (ast) => isProgram(ast) ? ast : program([
29
- maybeStatement(ast),
30
- ]);
28
+ const maybeProgram = (ast) => isProgram(ast)
29
+ ? ast
30
+ : program([
31
+ maybeStatement(ast),
32
+ ]);
31
33
 
32
34
  export const maybeFile = (ast) => isFile(ast) ? ast : file(maybeProgram(ast));
33
35
 
@@ -14,19 +14,25 @@ export const TSTypeParameterDeclaration = (path, printer, semantics) => {
14
14
  printer,
15
15
  });
16
16
 
17
- const printAfterOpen = !isNewline ? noop : () => {
18
- indent.inc();
19
- print.breakline();
20
- };
17
+ const printAfterOpen = !isNewline
18
+ ? noop
19
+ : () => {
20
+ indent.inc();
21
+ print.breakline();
22
+ };
21
23
 
22
- const printAfterClose = !isNewline ? noop : () => {
23
- print.breakline();
24
- };
24
+ const printAfterClose = !isNewline
25
+ ? noop
26
+ : () => {
27
+ print.breakline();
28
+ };
25
29
 
26
- const printBeforeClose = !isNewline ? noop : () => {
27
- indent.dec();
28
- print.breakline();
29
- };
30
+ const printBeforeClose = !isNewline
31
+ ? noop
32
+ : () => {
33
+ indent.dec();
34
+ print.breakline();
35
+ };
30
36
 
31
37
  printParams(path, printer, semantics, {
32
38
  printSpace,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@putout/printer",
3
- "version": "18.43.0",
3
+ "version": "18.44.0",
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",