@putout/printer 18.2.6 → 18.2.7

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,10 @@
1
+ 2026.03.08, v18.2.7
2
+
3
+ feature:
4
+ - c873574 @putout/printer: isIncreaseIndent: move out: newlinew -> indent
5
+ - d3672b6 @putout/printer: ArrayExpression: newline: isIncreaseIndent
6
+ - 642c80f @putout/printer: ArrayExpression: indent: isArrayIndented: type-check
7
+
1
8
  2026.03.08, v18.2.6
2
9
 
3
10
  feature:
@@ -12,13 +12,13 @@ import {
12
12
  callWithPrev,
13
13
  } from '#is';
14
14
  import {
15
- isIncreaseIndent,
16
15
  isCurrentNewLine,
17
16
  isMultiLine,
18
17
  } from './newline.js';
19
18
  import {
20
19
  isArrayInsideArray,
21
- isArrayIndented,
20
+ isIncreaseIndent,
21
+ isIndentElement,
22
22
  } from './indent.js';
23
23
  import {isObjectAfterSimple} from './is-object-after-simple.js';
24
24
  import {
@@ -93,7 +93,7 @@ export const ArrayExpression = {
93
93
 
94
94
  print('[');
95
95
 
96
- const indented = isArrayIndented(path);
96
+ const indented = isIndentElement(path);
97
97
 
98
98
  maybe.indent.inc(indented && shouldIncreaseIndent);
99
99
 
@@ -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,21 @@ 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 isIndentElement = createTypeChecker([
57
+ ['-', isArrayInsideArray],
58
+ ['-', isObjectAfterString],
59
+ ['+: -> !', isTwoLongStrings],
60
+ ['+: -> !', isInsideArray],
61
+ ]);
62
+
63
+ export const isIncreaseIndent = createTypeChecker([
64
+ ['-: node.elements.length -> !', Boolean],
65
+ ['+', isBooleanAndObject],
66
+ ['-', isInsideCallLoop],
67
+ ['+: node.elements.0 -> ObjectExpression'],
68
+ ['-: node.elements.1 -> SpreadElement'],
69
+ ['+', isStringAndObject],
70
+ ]);
37
71
 
38
72
  export function isArrayInsideArray(path) {
39
73
  if (!path.isArrayExpression() || !path.parentPath.isArrayExpression())
@@ -51,11 +85,3 @@ export function isArrayInsideArray(path) {
51
85
  return length <= 3 && length !== 1;
52
86
  }
53
87
 
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.7",
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",