@putout/printer 6.11.2 → 6.11.4
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
|
@@ -12,6 +12,7 @@ const {
|
|
|
12
12
|
isNullLiteral,
|
|
13
13
|
isStringLiteral,
|
|
14
14
|
isSpreadElement,
|
|
15
|
+
isNumericLiteral,
|
|
15
16
|
} = require('@putout/babel').types;
|
|
16
17
|
|
|
17
18
|
const {
|
|
@@ -21,6 +22,7 @@ const {
|
|
|
21
22
|
isCoupleLines,
|
|
22
23
|
isStringAndArray,
|
|
23
24
|
isIdentifierAndIdentifier,
|
|
25
|
+
satisfy,
|
|
24
26
|
} = require('../../is');
|
|
25
27
|
|
|
26
28
|
const {round} = Math;
|
|
@@ -47,17 +49,26 @@ const isSimpleAndObject = ([a, b]) => isSimple(a) && isObjectExpression(b);
|
|
|
47
49
|
const ONE_LINE = false;
|
|
48
50
|
const MULTI_LINE = true;
|
|
49
51
|
|
|
52
|
+
const isOneLine = satisfy([
|
|
53
|
+
isOneSimple,
|
|
54
|
+
isOneSpread,
|
|
55
|
+
isIdentifierAndIdentifier,
|
|
56
|
+
isBooleanAndSimple,
|
|
57
|
+
isNullAndSimple,
|
|
58
|
+
isSimpleAndCall,
|
|
59
|
+
isTwoStringsDifferentLength,
|
|
60
|
+
isStringAndArray,
|
|
61
|
+
isStringAndMember,
|
|
62
|
+
isStringAndIdentifier,
|
|
63
|
+
isIdentifierAndString,
|
|
64
|
+
isSimpleAndObject,
|
|
65
|
+
]);
|
|
66
|
+
|
|
50
67
|
module.exports.isMultiLine = (path, {elements, maxElementsInOneLine}) => {
|
|
51
68
|
if (elements.length > 3 && !isObjectExpression(elements[0]))
|
|
52
69
|
return MULTI_LINE;
|
|
53
70
|
|
|
54
|
-
if (
|
|
55
|
-
return ONE_LINE;
|
|
56
|
-
|
|
57
|
-
if (isOneSpread(elements))
|
|
58
|
-
return ONE_LINE;
|
|
59
|
-
|
|
60
|
-
if (elements.length === 2 && isIdentifierAndIdentifier(elements))
|
|
71
|
+
if (isOneLine(elements))
|
|
61
72
|
return ONE_LINE;
|
|
62
73
|
|
|
63
74
|
if (isCallInsideArrow(path))
|
|
@@ -69,48 +80,33 @@ module.exports.isMultiLine = (path, {elements, maxElementsInOneLine}) => {
|
|
|
69
80
|
if (isInsideLoop(path))
|
|
70
81
|
return ONE_LINE;
|
|
71
82
|
|
|
72
|
-
if (isBooleanAndSimple(elements))
|
|
73
|
-
return ONE_LINE;
|
|
74
|
-
|
|
75
|
-
if (isNullAndSimple(elements))
|
|
76
|
-
return ONE_LINE;
|
|
77
|
-
|
|
78
|
-
if (isSimpleAndCall(elements))
|
|
79
|
-
return ONE_LINE;
|
|
80
|
-
|
|
81
83
|
if (isShortTwoSimplesInsideCall(path, maxElementsInOneLine))
|
|
82
84
|
return ONE_LINE;
|
|
83
85
|
|
|
84
|
-
if (isTwoStringsDifferentLength(elements))
|
|
85
|
-
return ONE_LINE;
|
|
86
|
-
|
|
87
86
|
if (isTwoSimplesInsideObjectProperty(path))
|
|
88
87
|
return ONE_LINE;
|
|
89
88
|
|
|
90
|
-
if (isStringAndArray(elements))
|
|
91
|
-
return ONE_LINE;
|
|
92
|
-
|
|
93
|
-
if (isStringAndMember(elements))
|
|
94
|
-
return ONE_LINE;
|
|
95
|
-
|
|
96
|
-
if (isStringAndIdentifier(elements))
|
|
97
|
-
return ONE_LINE;
|
|
98
|
-
|
|
99
|
-
if (isIdentifierAndString(elements))
|
|
100
|
-
return ONE_LINE;
|
|
101
|
-
|
|
102
|
-
if (isSimpleAndObject(elements))
|
|
103
|
-
return ONE_LINE;
|
|
104
|
-
|
|
105
89
|
if (isStringAndString(elements) && isParentIsArrayWithFirstArrayElement(path))
|
|
106
90
|
return ONE_LINE;
|
|
107
91
|
|
|
108
|
-
if (tooLong(path) || isCoupleLines(path)
|
|
92
|
+
if (tooLong(path) || isCoupleLines(path))
|
|
93
|
+
return MULTI_LINE;
|
|
94
|
+
|
|
95
|
+
if (notNumbersInsideForOf(path))
|
|
109
96
|
return MULTI_LINE;
|
|
110
97
|
|
|
111
98
|
return ONE_LINE;
|
|
112
99
|
};
|
|
113
100
|
|
|
101
|
+
function notNumbersInsideForOf(path) {
|
|
102
|
+
const {elements} = path.node;
|
|
103
|
+
|
|
104
|
+
if (isNumbers(elements))
|
|
105
|
+
return false;
|
|
106
|
+
|
|
107
|
+
return !isForOf(path) && isLastArg(path) && !isParentProperty(path);
|
|
108
|
+
}
|
|
109
|
+
|
|
114
110
|
const isParentIsArrayWithFirstArrayElement = ({parentPath}) => {
|
|
115
111
|
if (!isArrayExpression(parentPath))
|
|
116
112
|
return false;
|
|
@@ -159,9 +155,7 @@ const isTwoSimplesInsideObjectProperty = (path) => {
|
|
|
159
155
|
return !isCoupleLines(path);
|
|
160
156
|
};
|
|
161
157
|
|
|
162
|
-
function isOneSimple(
|
|
163
|
-
const elements = path.get('elements');
|
|
164
|
-
|
|
158
|
+
function isOneSimple(elements) {
|
|
165
159
|
if (elements.length !== 1)
|
|
166
160
|
return false;
|
|
167
161
|
|
|
@@ -229,7 +223,7 @@ function isCallInsideArrow(path) {
|
|
|
229
223
|
|
|
230
224
|
function isNumbers(elements) {
|
|
231
225
|
for (const element of elements) {
|
|
232
|
-
if (
|
|
226
|
+
if (isNumericLiteral(element))
|
|
233
227
|
return true;
|
|
234
228
|
}
|
|
235
229
|
|
package/lib/tokenize/is.js
CHANGED
|
@@ -60,7 +60,14 @@ function isStringAndIdentifier([a, b]) {
|
|
|
60
60
|
return isStringLiteral(a) && isIdentifier(b);
|
|
61
61
|
}
|
|
62
62
|
|
|
63
|
-
module.exports.isIdentifierAndIdentifier = (
|
|
63
|
+
module.exports.isIdentifierAndIdentifier = (elements) => {
|
|
64
|
+
if (elements.length !== 2)
|
|
65
|
+
return false;
|
|
66
|
+
|
|
67
|
+
const [a, b] = elements;
|
|
68
|
+
|
|
69
|
+
return isIdentifier(a) && isIdentifier(b);
|
|
70
|
+
};
|
|
64
71
|
module.exports.isStringAndMember = ([a, b]) => isStringLiteral(a) && isMemberExpression(b);
|
|
65
72
|
module.exports.isIdentifierAndString = ([a, b]) => isIdentifier(a) && isStringLiteral(b);
|
|
66
73
|
module.exports.isStringAndArray = ([a, b]) => {
|
package/package.json
CHANGED