@putout/printer 18.2.8 → 18.2.10

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.10
2
+
3
+ feature:
4
+ - 7a73310 @putout/printer: ArrayExpresison: maybeSecondIndent
5
+ - cfcf1ce @putout/printer: ArrayExpression: isSecondIndent
6
+ - 0acb26a @putout/printer: ArrayExpression: isSecondIndent
7
+
8
+ 2026.03.08, v18.2.9
9
+
10
+ feature:
11
+ - f61d5f4 @putout/printer: ArrayExpression: isHideIndent
12
+
1
13
  2026.03.08, v18.2.8
2
14
 
3
15
  feature:
@@ -4,11 +4,9 @@ import {
4
4
  isCoupleLines,
5
5
  isStringAndIdentifier,
6
6
  isIdentifierAndIdentifier,
7
- isStringAndArray,
8
7
  isSimpleAndNotEmptyObject,
9
8
  isNextObject,
10
9
  callWithNext,
11
- isInsideArray,
12
10
  callWithPrev,
13
11
  } from '#is';
14
12
  import {
@@ -17,8 +15,8 @@ import {
17
15
  } from './newline.js';
18
16
  import {isObjectAfterSimple} from './is-object-after-simple.js';
19
17
  import {
20
- isArrayInsideArray,
21
18
  isNeedIndent,
19
+ maybeSecondIndent,
22
20
  } from './indent.js';
23
21
  import {
24
22
  beforeIf,
@@ -28,17 +26,12 @@ import {
28
26
  const {
29
27
  isObjectExpression,
30
28
  isSpreadElement,
31
- isStringLiteral,
32
29
  isIdentifier,
33
30
  isFunction,
34
31
  isCallExpression,
35
32
  isObjectProperty,
36
33
  } = types;
37
34
 
38
- const isNextString = (path) => isStringLiteral(path.getNextSibling());
39
- const isPrevString = (path) => isStringLiteral(path.getPrevSibling());
40
- const isAroundStrings = (path) => isNextString(path) || isPrevString(path);
41
-
42
35
  const isSpreadBeforeObject = (a) => {
43
36
  if (!a.isObjectExpression())
44
37
  return false;
@@ -80,7 +73,9 @@ export const ArrayExpression = {
80
73
  before(path, {print}) {
81
74
  print.breakline();
82
75
  },
83
- print(path, {print, maybe}, semantics) {
76
+ print(path, printer, semantics) {
77
+ const {print, maybe} = printer;
78
+
84
79
  const {
85
80
  maxElementsInOneLine,
86
81
  trailingComma,
@@ -124,26 +119,14 @@ export const ArrayExpression = {
124
119
 
125
120
  if (!is && index < n) {
126
121
  print(',');
127
-
128
- if (isSpaceAfterComa(element))
129
- print.space();
122
+ maybe.print.space(isSpaceAfterComa(element));
130
123
  }
131
124
  }
132
125
 
133
126
  maybe.indent.dec(needIndent);
134
-
135
- const parentElements = path.parentPath.get('elements');
136
-
137
- if (isInsideArray(path) && isStringAndArray(path.parentPath)) {
138
- const parentCountTwo = parentElements.length === 2;
139
- const isHideIdent = !isAroundStrings(path) || parentCountTwo;
140
-
141
- maybe.indent.dec(isHideIdent);
142
- maybe.indent(elements.length && needsNewline);
143
- maybe.indent.inc(isHideIdent);
144
- } else if (!isArrayInsideArray(path) && !isObjectExpression(elements.at(-1))) {
145
- maybe.indent(elements.length && needsNewline);
146
- }
127
+ maybeSecondIndent(path, printer, semantics, {
128
+ needsNewline,
129
+ });
147
130
 
148
131
  if (isSimpleAndNotEmptyObject(path) && !isSpreadElement(elements.at(-1)) && !isCallExpression(elements.at(-1))) {
149
132
  print(',');
@@ -1,6 +1,10 @@
1
1
  import {types} from '@putout/babel';
2
- import {isInsideArray, isInsideCall} from '#is';
3
2
  import {createTypeChecker} from '#type-checker';
3
+ import {
4
+ isInsideArray,
5
+ isInsideCall,
6
+ isStringAndArray,
7
+ } from '#is';
4
8
 
5
9
  const isTwoLongStrings = (path) => {
6
10
  const [a, b] = path.node.elements;
@@ -89,3 +93,40 @@ export function isArrayInsideArray(path) {
89
93
 
90
94
  return length <= 3 && length !== 1;
91
95
  }
96
+
97
+ const isTwo = (a) => a === 2;
98
+
99
+ export const isHideIndent = createTypeChecker([
100
+ ['-: -> !', isInsideArray],
101
+ ['-: parentPath -> !', isStringAndArray],
102
+ ['+: parentPath.node.elements.length', isTwo],
103
+ ]);
104
+
105
+ const isLastElementObjectExpression = ({node}) => isObjectExpression(node.elements.at(-1));
106
+
107
+ const isNeedsNewlineOption = (a, {needsNewline}) => needsNewline;
108
+ const isNeedsToHideIndentOption = (a, {needsToHideIndent}) => needsToHideIndent;
109
+
110
+ export const isSecondIndent = createTypeChecker([
111
+ ['-: -> !', isNeedsNewlineOption],
112
+ ['+', isNeedsToHideIndentOption],
113
+ ['-: ->', isArrayInsideArray],
114
+ ['+: -> !', isLastElementObjectExpression],
115
+ ]);
116
+
117
+ export function maybeSecondIndent(path, printer, semantics, options) {
118
+ const {maybe, indent} = printer;
119
+ const {needsNewline} = options;
120
+ const needsToHideIndent = isHideIndent(path);
121
+
122
+ const needsToMakeSecondIndent = isSecondIndent(path, {
123
+ needsNewline,
124
+ needsToHideIndent,
125
+ });
126
+
127
+ if (needsToMakeSecondIndent) {
128
+ maybe.indent.dec(needsToHideIndent);
129
+ indent();
130
+ maybe.indent.inc(needsToHideIndent);
131
+ }
132
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@putout/printer",
3
- "version": "18.2.8",
3
+ "version": "18.2.10",
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",