@putout/printer 18.2.6 → 18.2.8

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,15 @@
1
+ 2026.03.08, v18.2.8
2
+
3
+ feature:
4
+ - 39d5af8 @putout/printer: ArrayExpression: isNeedIndent
5
+
6
+ 2026.03.08, v18.2.7
7
+
8
+ feature:
9
+ - c873574 @putout/printer: isIncreaseIndent: move out: newlinew -> indent
10
+ - d3672b6 @putout/printer: ArrayExpression: newline: isIncreaseIndent
11
+ - 642c80f @putout/printer: ArrayExpression: indent: isArrayIndented: type-check
12
+
1
13
  2026.03.08, v18.2.6
2
14
 
3
15
  feature:
@@ -12,15 +12,14 @@ import {
12
12
  callWithPrev,
13
13
  } from '#is';
14
14
  import {
15
- isIncreaseIndent,
16
15
  isCurrentNewLine,
17
16
  isMultiLine,
18
17
  } from './newline.js';
18
+ import {isObjectAfterSimple} from './is-object-after-simple.js';
19
19
  import {
20
20
  isArrayInsideArray,
21
- isArrayIndented,
21
+ isNeedIndent,
22
22
  } from './indent.js';
23
- import {isObjectAfterSimple} from './is-object-after-simple.js';
24
23
  import {
25
24
  beforeIf,
26
25
  isInsideOneElementArray,
@@ -89,13 +88,12 @@ export const ArrayExpression = {
89
88
  } = semantics;
90
89
 
91
90
  const elements = path.get('elements');
92
- const shouldIncreaseIndent = !isIncreaseIndent(path);
93
91
 
94
92
  print('[');
95
93
 
96
- const indented = isArrayIndented(path);
94
+ const needIndent = isNeedIndent(path);
97
95
 
98
- maybe.indent.inc(indented && shouldIncreaseIndent);
96
+ maybe.indent.inc(needIndent);
99
97
 
100
98
  const needsNewline = isMultiLine(path, {
101
99
  maxElementsInOneLine,
@@ -132,7 +130,7 @@ export const ArrayExpression = {
132
130
  }
133
131
  }
134
132
 
135
- maybe.indent.dec(indented && shouldIncreaseIndent);
133
+ maybe.indent.dec(needIndent);
136
134
 
137
135
  const parentElements = path.parentPath.get('elements');
138
136
 
@@ -1,14 +1,46 @@
1
1
  import {types} from '@putout/babel';
2
- import {isIndented, isInsideArray} from '#is';
2
+ import {isInsideArray, isInsideCall} from '#is';
3
+ import {createTypeChecker} from '#type-checker';
4
+
5
+ const isTwoLongStrings = (path) => {
6
+ const [a, b] = path.node.elements;
7
+ const LONG_STRING = 20;
8
+
9
+ if (!isStringLiteral(a) || !isStringLiteral(b))
10
+ return false;
11
+
12
+ return a.value.length > LONG_STRING;
13
+ };
3
14
 
4
15
  const {
5
16
  isStringLiteral,
6
17
  isArrayExpression,
7
18
  isObjectExpression,
8
19
  isTemplateLiteral,
20
+ isBooleanLiteral,
9
21
  } = types;
10
22
 
11
- const isObjectAfterString = ([first, second]) => {
23
+ const isInsideCallLoop = createTypeChecker([
24
+ ['-: -> !', isInsideCall],
25
+ ['+: parentPath.parentPath -> ForOfStatement'],
26
+ ]);
27
+
28
+ const isStringAndObject = (path) => {
29
+ const {elements} = path.node;
30
+ const first = elements.at(0);
31
+ const last = elements.at(-1);
32
+
33
+ return isStringLiteral(first) && isObjectExpression(last);
34
+ };
35
+
36
+ const isBooleanAndObject = (path) => {
37
+ const [a, b] = path.node.elements;
38
+ return isBooleanLiteral(a) && isObjectExpression(b);
39
+ };
40
+
41
+ const isObjectAfterString = (path) => {
42
+ const [first, second] = path.node.elements;
43
+
12
44
  if (!first || !second)
13
45
  return false;
14
46
 
@@ -21,19 +53,26 @@ const isObjectAfterString = ([first, second]) => {
21
53
  return isTemplateLiteral(first);
22
54
  };
23
55
 
24
- export const isArrayIndented = (path) => {
25
- const elements = path.get('elements');
26
-
27
- if (isArrayInsideArray(path))
28
- return false;
29
-
30
- const [first] = elements;
31
-
32
- if (isObjectAfterString(elements))
33
- return false;
34
-
35
- return !isTwoLongStrings(elements) || !isInsideArray(path) && isIndented(first);
36
- };
56
+ export const isIncreaseIndent = createTypeChecker([
57
+ ['-: node.elements.length -> !', Boolean],
58
+ ['+', isBooleanAndObject],
59
+ ['-', isInsideCallLoop],
60
+ ['+: node.elements.0 -> ObjectExpression'],
61
+ ['-: node.elements.1 -> SpreadElement'],
62
+ ['+', isStringAndObject],
63
+ ]);
64
+
65
+ export const isIndentElement = createTypeChecker([
66
+ ['-', isArrayInsideArray],
67
+ ['-', isObjectAfterString],
68
+ ['+: -> !', isTwoLongStrings],
69
+ ['+: -> !', isInsideArray],
70
+ ]);
71
+
72
+ export const isNeedIndent = createTypeChecker([
73
+ ['-: -> !', isIndentElement],
74
+ ['+: -> !', isIncreaseIndent],
75
+ ]);
37
76
 
38
77
  export function isArrayInsideArray(path) {
39
78
  if (!path.isArrayExpression() || !path.parentPath.isArrayExpression())
@@ -50,12 +89,3 @@ export function isArrayInsideArray(path) {
50
89
 
51
90
  return length <= 3 && length !== 1;
52
91
  }
53
-
54
- const isTwoLongStrings = ([a, b]) => {
55
- const LONG_STRING = 20;
56
-
57
- if (!isStringLiteral(a) || !isStringLiteral(b))
58
- return false;
59
-
60
- return a.node.value.length > LONG_STRING;
61
- };
@@ -12,6 +12,7 @@ import {
12
12
  isInsideCall,
13
13
  isInsideArray,
14
14
  } from '#is';
15
+ import {isIncreaseIndent} from './indent.js';
15
16
 
16
17
  const isParentProperty = (path) => path.find(isObjectProperty);
17
18
 
@@ -111,8 +112,6 @@ const isBooleanAndSimple = (path) => {
111
112
  return isBooleanLiteral(a) && isSimple(b);
112
113
  };
113
114
 
114
- const isBooleanAndObject = ([a, b]) => isBooleanLiteral(a) && isObjectExpression(b);
115
-
116
115
  const isNullAndSimple = (path) => {
117
116
  const {elements} = path.node;
118
117
  const [a, b] = elements;
@@ -306,39 +305,6 @@ function isNumbers(elements) {
306
305
  return false;
307
306
  }
308
307
 
309
- export function isIncreaseIndent(path) {
310
- const elements = path.get('elements');
311
-
312
- if (!elements.length)
313
- return false;
314
-
315
- if (isBooleanAndObject(elements))
316
- return true;
317
-
318
- if (isInsideCallLoop(path))
319
- return false;
320
-
321
- if (elements[0].isObjectExpression())
322
- return true;
323
-
324
- if (isSpreadElement(elements[1]))
325
- return false;
326
-
327
- return isStringAndObject(elements);
328
- }
329
-
330
- const isInsideCallLoop = createTypeChecker([
331
- ['-: -> !', isInsideCall],
332
- ['+: parentPath.parentPath -> ForOfStatement'],
333
- ]);
334
-
335
- const isStringAndObject = (elements) => {
336
- const first = elements.at(0);
337
- const last = elements.at(-1);
338
-
339
- return isStringLiteral(first) && isObjectExpression(last);
340
- };
341
-
342
308
  export const isCurrentNewLine = createTypeChecker([
343
309
  '+: -> SpreadElement',
344
310
  '+: -> !ObjectExpression',
@@ -72,15 +72,6 @@ export const isPrevBody = (path) => path
72
72
 
73
73
  export const isParentLast = (path) => isLast(path.parentPath);
74
74
 
75
- export const isIndented = (path = {}) => {
76
- const {parentPath, node} = path;
77
-
78
- if (!parentPath.node.loc)
79
- return true;
80
-
81
- return node.loc?.start.column !== parentPath.node.loc.start.column;
82
- };
83
-
84
75
  export function isCoupleLines(path) {
85
76
  const start = path.node?.loc?.start?.line;
86
77
  const end = path.node?.loc?.end?.line;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@putout/printer",
3
- "version": "18.2.6",
3
+ "version": "18.2.8",
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",