@putout/printer 18.47.4 → 18.48.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,14 @@
1
+ 2026.10.17, v18.48.0
2
+
3
+ feature:
4
+ - b8c5a8ef @putout/printer: jsx: indent: improve
5
+
6
+ 2026.10.04, v18.47.5
7
+
8
+ feature:
9
+ - 6c71fe95 @putout/printer: CallExpression: comment: interanl
10
+ - f4265854 @putout/printer: CallExpression: filled array
11
+
1
12
  2026.10.03, v18.47.4
2
13
 
3
14
  feature:
@@ -7,7 +7,7 @@ const isLast = (arg) => {
7
7
  const {length} = arg.parentPath.node.arguments;
8
8
  const n = length - 1;
9
9
 
10
- return arg.key === n;
10
+ return arg.__putout_printer_index === n;
11
11
  };
12
12
 
13
13
  const getFirstArg = (fn) => (path) => fn(path.get('arguments.0'));
@@ -66,13 +66,18 @@ export const CallExpression = maybeParens((path, printer, semantics) => {
66
66
 
67
67
  export const OptionalCallExpression = CallExpression;
68
68
 
69
- const isSpaceAfterArg = createTypeChecker([
69
+ const isSpaceBeforeArg = createTypeChecker([
70
70
  ['-: parentPath -> !', isMaxArgs],
71
71
  ['+: -> ArrayExpression'],
72
72
  ]);
73
73
 
74
- const isBreaklineAfterArg = createTypeChecker([
75
- ['-: -> ArrayExpression'],
74
+ const isFilledArray = createTypeChecker([
75
+ '-: -> !ArrayExpression',
76
+ '+: node.elements.length -> +',
77
+ ]);
78
+
79
+ const isBreaklineBeforeArg = createTypeChecker([
80
+ ['-', isFilledArray],
76
81
  ['+: parentPath', isMaxArgs],
77
82
  ['+', isMemberCallee],
78
83
  ['-: parentPath -> !', isMultiline],
@@ -94,6 +99,12 @@ const isBreaklineAfterAllArgs = createTypeChecker([
94
99
  ['+', getFirstArg(isMemberCallee)],
95
100
  ]);
96
101
 
102
+ const isSpaceAfterArg = createTypeChecker([
103
+ ['-: ->', isLast],
104
+ ['-: parentPath', isMaxArgs],
105
+ ['+: parentPath -> !', isMultiline],
106
+ ]);
107
+
97
108
  const isIndent = createTypeChecker([isMaxArgs, isMultiline]);
98
109
 
99
110
  function printArgs(path, printer, semantics) {
@@ -103,11 +114,13 @@ function printArgs(path, printer, semantics) {
103
114
  if (isIndent(path, semantics))
104
115
  indent.inc();
105
116
 
106
- for (const arg of args) {
107
- if (isSpaceAfterArg(arg, semantics))
117
+ for (const [i, arg] of args.entries()) {
118
+ arg.__putout_printer_index = i;
119
+
120
+ if (isSpaceBeforeArg(arg, semantics))
108
121
  print.space();
109
122
 
110
- if (isBreaklineAfterArg(arg, semantics))
123
+ if (isBreaklineBeforeArg(arg, semantics))
111
124
  print.breakline();
112
125
 
113
126
  print(arg);
@@ -115,7 +128,7 @@ function printArgs(path, printer, semantics) {
115
128
  if (isCommaAfterArg(arg, semantics))
116
129
  print(',');
117
130
 
118
- if (isSpace(arg, semantics))
131
+ if (isSpaceAfterArg(arg, semantics))
119
132
  print.space();
120
133
  }
121
134
 
@@ -126,12 +139,6 @@ function printArgs(path, printer, semantics) {
126
139
  print.breakline();
127
140
  }
128
141
 
129
- const isSpace = createTypeChecker([
130
- ['-: parentPath', isMultiline],
131
- ['-: parentPath', isMaxArgs],
132
- ['+: -> !', isLast],
133
- ]);
134
-
135
142
  function tooLong(path) {
136
143
  const args = parseArgs(path);
137
144
 
@@ -3,7 +3,7 @@ import {parseComments} from '#comments';
3
3
 
4
4
  export {JSXElement} from './jsx-element.js';
5
5
  export {JSXAttribute} from './jsx-attribute.js';
6
- export {JSXOpeningElement} from './jsx-opening-element.js';
6
+ export {JSXOpeningElement} from './jsx-opening-element/jsx-opening-element.js';
7
7
  export * from './jsx-fragment.js';
8
8
  export {JSXText} from './jsx-text/jsx-text.js';
9
9
 
@@ -0,0 +1,45 @@
1
+ import {types} from '@putout/babel';
2
+ import {createTypeChecker} from '#type-checker';
3
+ import {isCoupleLines} from '#is';
4
+
5
+ const {
6
+ isObjectProperty,
7
+ isCallExpression,
8
+ isJSXElement,
9
+ isJSXExpressionContainer,
10
+ isJSXFragment,
11
+ isLogicalExpression,
12
+ isFunction,
13
+ } = types;
14
+
15
+ const isIdentableParent = createTypeChecker([
16
+ isObjectProperty,
17
+ isCallExpression,
18
+ isJSXElement,
19
+ isJSXExpressionContainer,
20
+ isJSXFragment,
21
+ isLogicalExpression,
22
+ ]);
23
+
24
+ const hasJSXExpression = ({value}) => isJSXExpressionContainer(value);
25
+
26
+ const hasFnAttribute = (path) => {
27
+ for (const attribute of path.node.attributes.filter(hasJSXExpression)) {
28
+ if (isFunction(attribute.value.expression))
29
+ return true;
30
+ }
31
+
32
+ return false;
33
+ };
34
+
35
+ export const isIndentBefore = createTypeChecker([
36
+ ['+: parentPath.parentPath -> !', isIdentableParent],
37
+ ['-: parentPath.parentPath -> !CallExpression'],
38
+ ['+', hasFnAttribute],
39
+ ]);
40
+
41
+ export const isIndent = createTypeChecker([
42
+ ['-: -> !', isCoupleLines],
43
+ ['+: parentPath.parentPath -> JSXElement'],
44
+ ['+: parentPath.parentPath -> CallExpression'],
45
+ ]);
@@ -0,0 +1,26 @@
1
+ import {isCoupleLines} from '#is';
2
+ import {isIndent, isIndentBefore} from './indent.js';
3
+
4
+ export const JSXOpeningElement = (path, {print, maybe}) => {
5
+ const coupleLines = isCoupleLines(path);
6
+ const shouldIndent = isIndent(path);
7
+
8
+ maybe.indent.inc(shouldIndent);
9
+ maybe.indent(isIndentBefore(path));
10
+ print('<');
11
+ print('__name');
12
+
13
+ for (const attr of path.get('attributes')) {
14
+ maybe.print.space(!coupleLines);
15
+ print(attr);
16
+ }
17
+
18
+ if (isCoupleLines(path))
19
+ print.breakline();
20
+
21
+ if (path.node.selfClosing)
22
+ print('/');
23
+
24
+ print('>');
25
+ maybe.indent.dec(shouldIndent);
26
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@putout/printer",
3
- "version": "18.47.4",
3
+ "version": "18.48.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",
@@ -1,48 +0,0 @@
1
- import {isCoupleLines} from '#is';
2
-
3
- const isNotJSX = ({parentPath}) => {
4
- const grandPath = parentPath.parentPath;
5
-
6
- if (grandPath.isObjectProperty())
7
- return false;
8
-
9
- if (grandPath.isCallExpression())
10
- return false;
11
-
12
- if (grandPath.isJSXElement())
13
- return false;
14
-
15
- if (grandPath.isJSXExpressionContainer())
16
- return false;
17
-
18
- if (grandPath.isJSXFragment())
19
- return false;
20
-
21
- return !grandPath.isLogicalExpression();
22
- };
23
-
24
- export const JSXOpeningElement = (path, {print, maybe}) => {
25
- maybe.indent(isNotJSX(path));
26
- print('<');
27
- print('__name');
28
-
29
- const coupleLines = isCoupleLines(path);
30
- const noCoupleLines = !coupleLines;
31
- const shouldIndent = coupleLines && path.parentPath.parentPath.isJSXElement();
32
-
33
- maybe.indent.inc(shouldIndent);
34
-
35
- for (const attr of path.get('attributes')) {
36
- maybe.print.space(noCoupleLines);
37
- print(attr);
38
- }
39
-
40
- if (isCoupleLines(path))
41
- print.breakline();
42
-
43
- if (path.node.selfClosing)
44
- print('/');
45
-
46
- print('>');
47
- maybe.indent.dec(shouldIndent);
48
- };