@putout/printer 18.1.4 → 18.1.6

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.03.07, v18.1.6
2
+
3
+ feature:
4
+ - b94489a @putout/printer: ArrayExpression: no new line when single element
5
+
6
+ 2026.03.07, v18.1.5
7
+
8
+ feature:
9
+ - 142e7b8 @putout/printer: is: getNext -> callWithNext
10
+
1
11
  2026.03.06, v18.1.4
2
12
 
3
13
  fix:
@@ -7,7 +7,7 @@ import {
7
7
  isStringAndArray,
8
8
  isSimpleAndNotEmptyObject,
9
9
  isNextObject,
10
- getNext,
10
+ callWithNext,
11
11
  isInsideArray,
12
12
  } from '#is';
13
13
  import {
@@ -64,14 +64,14 @@ const isSpreadBeforeObject = (a) => {
64
64
  };
65
65
 
66
66
  const isSimpleBetweenObjects = createTypeChecker([
67
- ['+', getNext(isObjectExpression)],
67
+ ['+', callWithNext(isObjectExpression)],
68
68
  ['-', isSpreadElement],
69
69
  ['-', isIdentifier],
70
70
  ['+: -> !', isCallExpression],
71
71
  ]);
72
72
 
73
73
  const isSpaceAfterComa = createTypeChecker([
74
- getNext(isSimpleBetweenObjects),
74
+ callWithNext(isSimpleBetweenObjects),
75
75
  '+: -> !ObjectExpression',
76
76
  ]);
77
77
 
@@ -12,15 +12,11 @@ import {
12
12
  isInsideCall,
13
13
  isInsideArray,
14
14
  } from '#is';
15
- import {isInsideForOf} from '../object-pattern/is.js';
16
15
 
17
- const isLastArg = ({parentPath}) => !parentPath.isCallExpression();
18
16
  const isParentProperty = (path) => path.find(isObjectProperty);
19
17
 
20
18
  const isNumbersArray = createTypeChecker([
21
- ['-: node.elements', isNumbers],
22
- ['-', isInsideForOf],
23
- ['-: -> !', isLastArg],
19
+ ['-: node.elements -> !', isNumbers],
24
20
  ['+: -> !', isParentProperty],
25
21
  ]);
26
22
 
@@ -140,12 +136,11 @@ const isSiblingIsArray = (path) => {
140
136
  .isArrayExpression();
141
137
  };
142
138
 
143
- const isEmptyArray = (path) => !path.node.elements.length;
144
-
145
139
  const isMoreThenMaxLiteralLength = (path, {maxElementLengthInOneLine}) => {
146
- const [first] = path.node.elements;
140
+ const {elements} = path.node;
141
+ const [first] = elements;
147
142
 
148
- if (!first.value)
143
+ if (!isStringLiteral(first))
149
144
  return false;
150
145
 
151
146
  return first.value.length > maxElementLengthInOneLine;
@@ -167,28 +162,16 @@ const hasObjects = (path) => {
167
162
  return literals.length;
168
163
  };
169
164
 
165
+ const isLessThenTwo = (a) => a < 2;
166
+
170
167
  const isMoreThenMaxElementLengthInOneLine = createTypeChecker([
171
- ['-', isEmptyArray],
168
+ ['-: node.elements.length', isLessThenTwo],
172
169
  ['-: -> !', isInsideCall],
173
170
  ['-', hasObjects],
174
171
  ['+', isMoreThenMaxLiteralLength],
175
172
  ['+', isMoreThenMaxIdentifierLength],
176
173
  ]);
177
174
 
178
- function isMaxElementLengthInOneLine(path, {maxElementLengthInOneLine}) {
179
- const elements = path.get('elements');
180
-
181
- if (elements.length > 1)
182
- return false;
183
-
184
- const [first] = elements;
185
-
186
- if (!isIdentifier(first))
187
- return false;
188
-
189
- return first.node.name.length < maxElementLengthInOneLine;
190
- }
191
-
192
175
  const isElementsMoreThenMax = (path, {maxElementsInOneLine}) => {
193
176
  const {elements} = path.node;
194
177
  return elements.length > maxElementsInOneLine;
@@ -210,9 +193,8 @@ const isElementsMoreThenMaxWithFirstString = createTypeChecker([
210
193
  ]);
211
194
 
212
195
  export const isMultiLine = createTypeChecker([
213
- ['-', isMaxElementLengthInOneLine],
214
- isMoreThenMaxElementLengthInOneLine,
215
- isElementsMoreThenMaxWithFirstString,
196
+ ['+', isMoreThenMaxElementLengthInOneLine],
197
+ ['+', isElementsMoreThenMaxWithFirstString],
216
198
  isElementsMoreThenThreeWithNotFirstObject,
217
199
  isSimpleAndNotEmptyObject,
218
200
  ['-', isOneSimple],
@@ -236,7 +218,7 @@ export const isMultiLine = createTypeChecker([
236
218
  ['-', isStringsInsideArray],
237
219
  tooLong,
238
220
  isCoupleLines,
239
- isNumbersArray,
221
+ ['-', isNumbersArray],
240
222
  ]);
241
223
 
242
224
  function isOneSimple(path) {
@@ -2,7 +2,7 @@ import {types} from '@putout/babel';
2
2
  import {printParams} from '#print-params';
3
3
  import {markAfter} from '#mark';
4
4
  import {
5
- getNext,
5
+ callWithNext,
6
6
  isNext,
7
7
  isNextParent,
8
8
  } from '#is';
@@ -17,9 +17,9 @@ const {
17
17
  const hasFnBody = ({node}) => node.body.body.length;
18
18
 
19
19
  const isIndentAfter = createTypeChecker([
20
- ['+', getNext(isFunctionDeclaration)],
20
+ ['+', callWithNext(isFunctionDeclaration)],
21
21
  ['+', isNext],
22
- ['-: -> !', getNext(isExpressionStatement)],
22
+ ['-: -> !', callWithNext(isExpressionStatement)],
23
23
  ]);
24
24
 
25
25
  const isNotInsideExportDefaultWithBody = createTypeChecker([
@@ -39,10 +39,7 @@ const {
39
39
 
40
40
  const isLogicalArgument = (path) => isLogicalExpression(path.node.argument);
41
41
 
42
- const isParens = createTypeChecker([
43
- isInsideBody,
44
- isInsideExpression,
45
- ]);
42
+ const isParens = createTypeChecker([isInsideBody, isInsideExpression]);
46
43
 
47
44
  const getCallee = (fn) => (a) => fn(a.get('callee'));
48
45
 
@@ -30,7 +30,7 @@ export const isInsideTSModuleBlock = ({parentPath}) => isTSModuleBlock(parentPat
30
30
 
31
31
  export const isInsideCall = ({parentPath}) => parentPath.isCallExpression();
32
32
  export const isInsideReturn = ({parentPath}) => parentPath.isReturnStatement();
33
- export const getNext = (fn) => (path) => fn(path.getNextSibling());
33
+ export const callWithNext = (fn) => (path) => fn(path.getNextSibling());
34
34
 
35
35
  export const isNext = (path) => {
36
36
  const next = path.getNextSibling();
@@ -8,7 +8,7 @@ import {
8
8
  hasTrailingComment,
9
9
  isCoupleLines,
10
10
  isInsideReturn,
11
- getNext,
11
+ callWithNext,
12
12
  hasLeadingComment,
13
13
  } from '#is';
14
14
  import {
@@ -27,7 +27,7 @@ const isCallInsideExpression = createTypeChecker([
27
27
 
28
28
  const isNextToAssignmentCall = createTypeChecker([
29
29
  '-: node.expression -> AssignmentExpression',
30
- ['+', getNext(isCallInsideExpression)],
30
+ ['+', callWithNext(isCallInsideExpression)],
31
31
  ]);
32
32
 
33
33
  const isBreaklineAfter = createTypeChecker([
@@ -44,7 +44,7 @@ const isNextStatementWithBlockComment = createTypeChecker([
44
44
 
45
45
  const isBreakline = createTypeChecker([
46
46
  isNewlineBetweenSiblings,
47
- getNext(isIfStatement),
47
+ callWithNext(isIfStatement),
48
48
  ]);
49
49
 
50
50
  const isIndent = createTypeChecker([
@@ -55,7 +55,7 @@ const isIndent = createTypeChecker([
55
55
 
56
56
  export const isIndentAfter = createTypeChecker([
57
57
  '-: node.expression -> !AssignmentExpression',
58
- ['+', getNext(hasLeadingComment)],
58
+ ['+', callWithNext(hasLeadingComment)],
59
59
  ]);
60
60
 
61
61
  export const ExpressionStatement = {
@@ -1,7 +1,7 @@
1
1
  import {
2
2
  isInsideLabel,
3
3
  exists,
4
- getNext,
4
+ callWithNext,
5
5
  } from '#is';
6
6
  import {markAfter} from '#mark';
7
7
 
@@ -40,7 +40,7 @@ export const ForStatement = {
40
40
  print('__body');
41
41
  maybe.indent.dec(is);
42
42
  },
43
- afterIf: getNext(exists),
43
+ afterIf: callWithNext(exists),
44
44
  after(path, {print}) {
45
45
  print.linebreak();
46
46
  markAfter(path);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@putout/printer",
3
- "version": "18.1.4",
3
+ "version": "18.1.6",
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",