@putout/printer 6.11.4 → 6.11.5

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
+ 2023.12.01, v6.11.5
2
+
3
+ feature:
4
+ - 96f6f4b @putout/printer: ArrayExpression: newline: isMultiLine
5
+
1
6
  2023.12.01, v6.11.4
2
7
 
3
8
  feature:
@@ -1,6 +1,39 @@
1
1
  'use strict';
2
2
 
3
3
  const {isSimple} = require('@putout/operate');
4
+ const isTwoStringsTupleAndParentIsArrayWithFirstArrayElement = (path) => {
5
+ const {elements} = path.node;
6
+
7
+ if (!isStringAndString(elements))
8
+ return false;
9
+
10
+ return isParentIsArrayWithFirstArrayElement(path);
11
+ };
12
+ const isLotsOfElementsFirstNotObject = (path) => {
13
+ const {elements} = path.node;
14
+ const [first] = elements;
15
+
16
+ return elements.length > 3 && !isObjectExpression(first);
17
+ };
18
+
19
+ const isTwoSimplesInsideObjectProperty = (path) => {
20
+ const {node, parentPath} = path;
21
+
22
+ const {elements} = node;
23
+ const {length} = elements;
24
+ const [a, b] = elements;
25
+
26
+ if (length > 2)
27
+ return false;
28
+
29
+ if (!parentPath.isObjectProperty())
30
+ return false;
31
+
32
+ if (!isStringLiteral(a) || !isStringLiteral(b))
33
+ return false;
34
+
35
+ return !isCoupleLines(path);
36
+ };
4
37
 
5
38
  const {
6
39
  isObjectExpression,
@@ -49,7 +82,7 @@ const isSimpleAndObject = ([a, b]) => isSimple(a) && isObjectExpression(b);
49
82
  const ONE_LINE = false;
50
83
  const MULTI_LINE = true;
51
84
 
52
- const isOneLine = satisfy([
85
+ const isOneLineElements = satisfy([
53
86
  isOneSimple,
54
87
  isOneSpread,
55
88
  isIdentifierAndIdentifier,
@@ -64,35 +97,34 @@ const isOneLine = satisfy([
64
97
  isSimpleAndObject,
65
98
  ]);
66
99
 
100
+ const isOneLinePath = satisfy([
101
+ isCallInsideArrow,
102
+ notIncreaseIndent,
103
+ isInsideLoop,
104
+ isTwoSimplesInsideObjectProperty,
105
+ isTwoStringsTupleAndParentIsArrayWithFirstArrayElement,
106
+ ]);
107
+
108
+ const isMultiLinePath = satisfy([
109
+ tooLong,
110
+ isCoupleLines,
111
+ notNumbersInsideForOf,
112
+ ]);
113
+
67
114
  module.exports.isMultiLine = (path, {elements, maxElementsInOneLine}) => {
68
- if (elements.length > 3 && !isObjectExpression(elements[0]))
115
+ if (isLotsOfElementsFirstNotObject(path))
69
116
  return MULTI_LINE;
70
117
 
71
- if (isOneLine(elements))
72
- return ONE_LINE;
73
-
74
- if (isCallInsideArrow(path))
75
- return ONE_LINE;
76
-
77
- if (notIncreaseIndent(path))
118
+ if (isOneLineElements(elements))
78
119
  return ONE_LINE;
79
120
 
80
- if (isInsideLoop(path))
121
+ if (isOneLinePath(path))
81
122
  return ONE_LINE;
82
123
 
83
124
  if (isShortTwoSimplesInsideCall(path, maxElementsInOneLine))
84
125
  return ONE_LINE;
85
126
 
86
- if (isTwoSimplesInsideObjectProperty(path))
87
- return ONE_LINE;
88
-
89
- if (isStringAndString(elements) && isParentIsArrayWithFirstArrayElement(path))
90
- return ONE_LINE;
91
-
92
- if (tooLong(path) || isCoupleLines(path))
93
- return MULTI_LINE;
94
-
95
- if (notNumbersInsideForOf(path))
127
+ if (isMultiLinePath(path))
96
128
  return MULTI_LINE;
97
129
 
98
130
  return ONE_LINE;
@@ -136,25 +168,6 @@ const isShortTwoSimplesInsideCall = (path, short) => {
136
168
  return length < short;
137
169
  };
138
170
 
139
- const isTwoSimplesInsideObjectProperty = (path) => {
140
- const {node, parentPath} = path;
141
-
142
- const {elements} = node;
143
- const {length} = elements;
144
- const [a, b] = elements;
145
-
146
- if (length > 2)
147
- return false;
148
-
149
- if (!parentPath.isObjectProperty())
150
- return false;
151
-
152
- if (!isStringLiteral(a) || !isStringLiteral(b))
153
- return false;
154
-
155
- return !isCoupleLines(path);
156
- };
157
-
158
171
  function isOneSimple(elements) {
159
172
  if (elements.length !== 1)
160
173
  return false;
@@ -278,3 +291,4 @@ module.exports.isCurrentNewLine = (path) => {
278
291
 
279
292
  return !path.isObjectExpression();
280
293
  };
294
+
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@putout/printer",
3
- "version": "6.11.4",
3
+ "version": "6.11.5",
4
4
  "type": "commonjs",
5
5
  "author": "coderaiser <mnemonic.enemy@gmail.com> (https://github.com/coderaiser)",
6
6
  "description": "Simplest possible opinionated Babel AST printer for 🐊Putout",