@putout/printer 18.2.9 → 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,10 @@
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
+
1
8
  2026.03.08, v18.2.9
2
9
 
3
10
  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,9 +15,8 @@ import {
17
15
  } from './newline.js';
18
16
  import {isObjectAfterSimple} from './is-object-after-simple.js';
19
17
  import {
20
- isArrayInsideArray,
21
- isHideIndent,
22
18
  isNeedIndent,
19
+ maybeSecondIndent,
23
20
  } from './indent.js';
24
21
  import {
25
22
  beforeIf,
@@ -76,7 +73,9 @@ export const ArrayExpression = {
76
73
  before(path, {print}) {
77
74
  print.breakline();
78
75
  },
79
- print(path, {print, maybe}, semantics) {
76
+ print(path, printer, semantics) {
77
+ const {print, maybe} = printer;
78
+
80
79
  const {
81
80
  maxElementsInOneLine,
82
81
  trailingComma,
@@ -120,23 +119,14 @@ export const ArrayExpression = {
120
119
 
121
120
  if (!is && index < n) {
122
121
  print(',');
123
-
124
- if (isSpaceAfterComa(element))
125
- print.space();
122
+ maybe.print.space(isSpaceAfterComa(element));
126
123
  }
127
124
  }
128
125
 
129
126
  maybe.indent.dec(needIndent);
130
-
131
- if (isInsideArray(path) && isStringAndArray(path.parentPath)) {
132
- const needsToHideIndent = isHideIndent(path);
133
-
134
- maybe.indent.dec(needsToHideIndent);
135
- maybe.indent(needsNewline);
136
- maybe.indent.inc(needsToHideIndent);
137
- } else if (!isArrayInsideArray(path) && !isObjectExpression(elements.at(-1))) {
138
- maybe.indent(needsNewline);
139
- }
127
+ maybeSecondIndent(path, printer, semantics, {
128
+ needsNewline,
129
+ });
140
130
 
141
131
  if (isSimpleAndNotEmptyObject(path) && !isSpreadElement(elements.at(-1)) && !isCallExpression(elements.at(-1))) {
142
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;
@@ -93,5 +97,36 @@ export function isArrayInsideArray(path) {
93
97
  const isTwo = (a) => a === 2;
94
98
 
95
99
  export const isHideIndent = createTypeChecker([
100
+ ['-: -> !', isInsideArray],
101
+ ['-: parentPath -> !', isStringAndArray],
96
102
  ['+: parentPath.node.elements.length', isTwo],
97
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.9",
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",