@putout/printer 18.2.8 → 18.2.9

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,8 @@
1
+ 2026.03.08, v18.2.9
2
+
3
+ feature:
4
+ - f61d5f4 @putout/printer: ArrayExpression: isHideIndent
5
+
1
6
  2026.03.08, v18.2.8
2
7
 
3
8
  feature:
@@ -18,6 +18,7 @@ import {
18
18
  import {isObjectAfterSimple} from './is-object-after-simple.js';
19
19
  import {
20
20
  isArrayInsideArray,
21
+ isHideIndent,
21
22
  isNeedIndent,
22
23
  } from './indent.js';
23
24
  import {
@@ -28,17 +29,12 @@ import {
28
29
  const {
29
30
  isObjectExpression,
30
31
  isSpreadElement,
31
- isStringLiteral,
32
32
  isIdentifier,
33
33
  isFunction,
34
34
  isCallExpression,
35
35
  isObjectProperty,
36
36
  } = types;
37
37
 
38
- const isNextString = (path) => isStringLiteral(path.getNextSibling());
39
- const isPrevString = (path) => isStringLiteral(path.getPrevSibling());
40
- const isAroundStrings = (path) => isNextString(path) || isPrevString(path);
41
-
42
38
  const isSpreadBeforeObject = (a) => {
43
39
  if (!a.isObjectExpression())
44
40
  return false;
@@ -132,17 +128,14 @@ export const ArrayExpression = {
132
128
 
133
129
  maybe.indent.dec(needIndent);
134
130
 
135
- const parentElements = path.parentPath.get('elements');
136
-
137
131
  if (isInsideArray(path) && isStringAndArray(path.parentPath)) {
138
- const parentCountTwo = parentElements.length === 2;
139
- const isHideIdent = !isAroundStrings(path) || parentCountTwo;
132
+ const needsToHideIndent = isHideIndent(path);
140
133
 
141
- maybe.indent.dec(isHideIdent);
142
- maybe.indent(elements.length && needsNewline);
143
- maybe.indent.inc(isHideIdent);
134
+ maybe.indent.dec(needsToHideIndent);
135
+ maybe.indent(needsNewline);
136
+ maybe.indent.inc(needsToHideIndent);
144
137
  } else if (!isArrayInsideArray(path) && !isObjectExpression(elements.at(-1))) {
145
- maybe.indent(elements.length && needsNewline);
138
+ maybe.indent(needsNewline);
146
139
  }
147
140
 
148
141
  if (isSimpleAndNotEmptyObject(path) && !isSpreadElement(elements.at(-1)) && !isCallExpression(elements.at(-1))) {
@@ -89,3 +89,9 @@ export function isArrayInsideArray(path) {
89
89
 
90
90
  return length <= 3 && length !== 1;
91
91
  }
92
+
93
+ const isTwo = (a) => a === 2;
94
+
95
+ export const isHideIndent = createTypeChecker([
96
+ ['+: parentPath.node.elements.length', isTwo],
97
+ ]);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@putout/printer",
3
- "version": "18.2.8",
3
+ "version": "18.2.9",
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",