@putout/printer 18.1.5 → 18.1.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,13 @@
1
+ 2026.03.07, v18.1.7
2
+
3
+ feature:
4
+ - 221c04e @putout/printer: ArrayExpression: one string
5
+
6
+ 2026.03.07, v18.1.6
7
+
8
+ feature:
9
+ - b94489a @putout/printer: ArrayExpression: no new line when single element
10
+
1
11
  2026.03.07, v18.1.5
2
12
 
3
13
  feature:
@@ -12,15 +12,11 @@ import {
12
12
  isInsideCall,
13
13
  isInsideArray,
14
14
  } from '#is';
15
- import {isInsideForOf} from '../object-pattern/is.js';
16
15
 
17
- const isLastArg = ({parentPath}) => !parentPath.isCallExpression();
18
16
  const isParentProperty = (path) => path.find(isObjectProperty);
19
17
 
20
18
  const isNumbersArray = createTypeChecker([
21
- ['-: node.elements', isNumbers],
22
- ['-', isInsideForOf],
23
- ['-: -> !', isLastArg],
19
+ ['-: node.elements -> !', isNumbers],
24
20
  ['+: -> !', isParentProperty],
25
21
  ]);
26
22
 
@@ -140,12 +136,11 @@ const isSiblingIsArray = (path) => {
140
136
  .isArrayExpression();
141
137
  };
142
138
 
143
- const isEmptyArray = (path) => !path.node.elements.length;
144
-
145
139
  const isMoreThenMaxLiteralLength = (path, {maxElementLengthInOneLine}) => {
146
- const [first] = path.node.elements;
140
+ const {elements} = path.node;
141
+ const [first] = elements;
147
142
 
148
- if (!first.value)
143
+ if (!isStringLiteral(first))
149
144
  return false;
150
145
 
151
146
  return first.value.length > maxElementLengthInOneLine;
@@ -167,28 +162,16 @@ const hasObjects = (path) => {
167
162
  return literals.length;
168
163
  };
169
164
 
165
+ const isLessThenTwo = (a) => a < 2;
166
+
170
167
  const isMoreThenMaxElementLengthInOneLine = createTypeChecker([
171
- ['-', isEmptyArray],
168
+ ['-: node.elements.length', isLessThenTwo],
172
169
  ['-: -> !', isInsideCall],
173
170
  ['-', hasObjects],
174
171
  ['+', isMoreThenMaxLiteralLength],
175
172
  ['+', isMoreThenMaxIdentifierLength],
176
173
  ]);
177
174
 
178
- function isMaxElementLengthInOneLine(path, {maxElementLengthInOneLine}) {
179
- const elements = path.get('elements');
180
-
181
- if (elements.length > 1)
182
- return false;
183
-
184
- const [first] = elements;
185
-
186
- if (!isIdentifier(first))
187
- return false;
188
-
189
- return first.node.name.length < maxElementLengthInOneLine;
190
- }
191
-
192
175
  const isElementsMoreThenMax = (path, {maxElementsInOneLine}) => {
193
176
  const {elements} = path.node;
194
177
  return elements.length > maxElementsInOneLine;
@@ -209,10 +192,18 @@ const isElementsMoreThenMaxWithFirstString = createTypeChecker([
209
192
  isElementsMoreThenMax,
210
193
  ]);
211
194
 
195
+ const isOne = (a) => a === 1;
196
+ const isBody = ({node, parentPath}) => node === parentPath.node.body;
197
+
198
+ const isBodyWithOneElement = createTypeChecker([
199
+ ['-: node.elements.length -> !', isOne],
200
+ ['+', isBody],
201
+ ]);
202
+
212
203
  export const isMultiLine = createTypeChecker([
213
- ['-', isMaxElementLengthInOneLine],
214
- isMoreThenMaxElementLengthInOneLine,
215
- isElementsMoreThenMaxWithFirstString,
204
+ ['+', isBodyWithOneElement],
205
+ ['+', isMoreThenMaxElementLengthInOneLine],
206
+ ['+', isElementsMoreThenMaxWithFirstString],
216
207
  isElementsMoreThenThreeWithNotFirstObject,
217
208
  isSimpleAndNotEmptyObject,
218
209
  ['-', isOneSimple],
@@ -236,7 +227,7 @@ export const isMultiLine = createTypeChecker([
236
227
  ['-', isStringsInsideArray],
237
228
  tooLong,
238
229
  isCoupleLines,
239
- isNumbersArray,
230
+ ['-', isNumbersArray],
240
231
  ]);
241
232
 
242
233
  function isOneSimple(path) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@putout/printer",
3
- "version": "18.1.5",
3
+ "version": "18.1.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",