@putout/printer 2.13.0 → 2.14.0
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 +10 -0
- package/lib/tokenize/expressions/array-expression/array-expression.js +1 -4
- package/lib/tokenize/expressions/array-expression/new-line.js +16 -12
- package/lib/tokenize/expressions/binary-expression/concatanate.js +1 -4
- package/lib/tokenize/expressions/object-expression/object-expression.js +1 -4
- package/lib/tokenize/expressions/object-pattern/object-pattern.js +1 -4
- package/lib/tokenize/statements/block-statement/block-statement.js +2 -8
- package/lib/tokenize/statements/export-declaration/export-default-declaration.js +1 -4
- package/lib/tokenize/statements/expression-statement.js +1 -4
- package/lib/tokenize/statements/for-of-statement.js +1 -6
- package/lib/tokenize/statements/if-statement/if-statement.js +1 -4
- package/lib/tokenize/statements/import-declaration/import-declaration.js +1 -4
- package/lib/tokenize/statements/variable-declaration/variable-declaration.js +1 -4
- package/lib/tokenize/statements/while-statement.js +1 -4
- package/lib/tokenize/typescript/ts-type-alias-declaration.js +1 -4
- package/lib/tokenize/typescript/ts-type-literal.js +1 -4
- package/package.json +1 -1
package/ChangeLog
CHANGED
|
@@ -21,10 +21,7 @@ const isTwoLongStrings = ([a, b]) => {
|
|
|
21
21
|
if (!a?.isStringLiteral() || !b?.isStringLiteral())
|
|
22
22
|
return false;
|
|
23
23
|
|
|
24
|
-
|
|
25
|
-
return true;
|
|
26
|
-
|
|
27
|
-
return false;
|
|
24
|
+
return a.node.value.length > LONG_STRING;
|
|
28
25
|
};
|
|
29
26
|
|
|
30
27
|
module.exports.ArrayExpression = {
|
|
@@ -11,6 +11,7 @@ const {
|
|
|
11
11
|
isBooleanLiteral,
|
|
12
12
|
isNullLiteral,
|
|
13
13
|
isStringLiteral,
|
|
14
|
+
isSpreadElement,
|
|
14
15
|
} = require('@babel/types');
|
|
15
16
|
|
|
16
17
|
const {
|
|
@@ -24,6 +25,15 @@ const {
|
|
|
24
25
|
|
|
25
26
|
const {round} = Math;
|
|
26
27
|
|
|
28
|
+
const isOneSpread = (elements) => {
|
|
29
|
+
if (elements.length > 1)
|
|
30
|
+
return false;
|
|
31
|
+
|
|
32
|
+
const [first] = elements;
|
|
33
|
+
|
|
34
|
+
return isSpreadElement(first);
|
|
35
|
+
};
|
|
36
|
+
|
|
27
37
|
const isSimpleAndCall = ([a, b]) => {
|
|
28
38
|
if (!isSimple(a))
|
|
29
39
|
return;
|
|
@@ -44,6 +54,9 @@ module.exports.isNewlineBetweenElements = (path, {elements, maxElementsInOneLine
|
|
|
44
54
|
if (isOneSimple(path))
|
|
45
55
|
return ONE_LINE;
|
|
46
56
|
|
|
57
|
+
if (isOneSpread(elements))
|
|
58
|
+
return ONE_LINE;
|
|
59
|
+
|
|
47
60
|
if (elements.length === 2 && isIdentifierAndIdentifier(elements))
|
|
48
61
|
return ONE_LINE;
|
|
49
62
|
|
|
@@ -157,10 +170,7 @@ function isTwoStringsDifferentLength(strings) {
|
|
|
157
170
|
}
|
|
158
171
|
|
|
159
172
|
function isInsideLoop(path) {
|
|
160
|
-
|
|
161
|
-
return false;
|
|
162
|
-
|
|
163
|
-
return true;
|
|
173
|
+
return path.parentPath.isForOfStatement();
|
|
164
174
|
}
|
|
165
175
|
|
|
166
176
|
function tooLong(path) {
|
|
@@ -219,20 +229,14 @@ function isIncreaseIndent(path) {
|
|
|
219
229
|
if (elements[0].isObjectExpression())
|
|
220
230
|
return true;
|
|
221
231
|
|
|
222
|
-
|
|
223
|
-
return true;
|
|
224
|
-
|
|
225
|
-
return false;
|
|
232
|
+
return isStringAndObject(elements);
|
|
226
233
|
}
|
|
227
234
|
|
|
228
235
|
function isInsideCallLoop(path) {
|
|
229
236
|
if (!path.parentPath.isCallExpression())
|
|
230
237
|
return false;
|
|
231
238
|
|
|
232
|
-
|
|
233
|
-
return false;
|
|
234
|
-
|
|
235
|
-
return true;
|
|
239
|
+
return path.parentPath.parentPath.isForOfStatement();
|
|
236
240
|
}
|
|
237
241
|
|
|
238
242
|
const isStringAndObject = (elements) => {
|
|
@@ -128,8 +128,5 @@ function shouldAddNewline(path) {
|
|
|
128
128
|
if (!isForOf(path) && !path.parentPath.isFunction() && n && checkLength(properties))
|
|
129
129
|
return true;
|
|
130
130
|
|
|
131
|
-
|
|
132
|
-
return true;
|
|
133
|
-
|
|
134
|
-
return false;
|
|
131
|
+
return parentPath.isObjectProperty();
|
|
135
132
|
}
|
|
@@ -79,10 +79,7 @@ function shouldAddNewlineAfter(path) {
|
|
|
79
79
|
if (isLast(path))
|
|
80
80
|
return false;
|
|
81
81
|
|
|
82
|
-
|
|
83
|
-
return false;
|
|
84
|
-
|
|
85
|
-
return true;
|
|
82
|
+
return !isNextIfAlternate(path);
|
|
86
83
|
}
|
|
87
84
|
|
|
88
85
|
function isNextIfAlternate(path) {
|
|
@@ -103,8 +100,5 @@ function isTry({parentPath}) {
|
|
|
103
100
|
if (parentPath.isTryStatement())
|
|
104
101
|
return true;
|
|
105
102
|
|
|
106
|
-
|
|
107
|
-
return true;
|
|
108
|
-
|
|
109
|
-
return false;
|
|
103
|
+
return parentPath.parentPath?.isTryStatement();
|
|
110
104
|
}
|
|
@@ -13,10 +13,7 @@ function shouldAddSemi(path) {
|
|
|
13
13
|
if (path.isClassDeclaration())
|
|
14
14
|
return false;
|
|
15
15
|
|
|
16
|
-
|
|
17
|
-
return false;
|
|
18
|
-
|
|
19
|
-
return true;
|
|
16
|
+
return !path.isFunctionDeclaration();
|
|
20
17
|
}
|
|
21
18
|
|
|
22
19
|
module.exports.ExportDefaultDeclaration = {
|
|
@@ -57,10 +57,7 @@ module.exports.ExpressionStatement = {
|
|
|
57
57
|
if (hasTrailingComment(path) && isLast(path))
|
|
58
58
|
return true;
|
|
59
59
|
|
|
60
|
-
|
|
61
|
-
return true;
|
|
62
|
-
|
|
63
|
-
return false;
|
|
60
|
+
return isBeforeElse(path);
|
|
64
61
|
},
|
|
65
62
|
after(path, {print, maybe, store}) {
|
|
66
63
|
if (hasTrailingComment(path) && isLast(path) && isCoupleLines(path)) {
|
|
@@ -55,12 +55,7 @@ module.exports.ForOfStatement = {
|
|
|
55
55
|
|
|
56
56
|
maybe.markAfter(isMarkedAfter(bodyPath), path);
|
|
57
57
|
},
|
|
58
|
-
afterIf: (path) =>
|
|
59
|
-
if (isNext(path))
|
|
60
|
-
return true;
|
|
61
|
-
|
|
62
|
-
return false;
|
|
63
|
-
},
|
|
58
|
+
afterIf: (path) => isNext(path),
|
|
64
59
|
after(path, {print}) {
|
|
65
60
|
print.linebreak();
|
|
66
61
|
markAfter(path);
|
|
@@ -96,10 +96,7 @@ module.exports.ImportDeclaration = {
|
|
|
96
96
|
if (isLast(path))
|
|
97
97
|
return false;
|
|
98
98
|
|
|
99
|
-
|
|
100
|
-
return false;
|
|
101
|
-
|
|
102
|
-
return true;
|
|
99
|
+
return !path.getNextSibling().isImportDeclaration();
|
|
103
100
|
},
|
|
104
101
|
after(path, {print}) {
|
|
105
102
|
print.newline();
|
|
@@ -149,10 +149,7 @@ function shouldAddNewlineBefore(path) {
|
|
|
149
149
|
if (prevPath.isStatement() && !prevPath.isExpressionStatement() && !prevPath.isBlockStatement())
|
|
150
150
|
return false;
|
|
151
151
|
|
|
152
|
-
|
|
153
|
-
return true;
|
|
154
|
-
|
|
155
|
-
return false;
|
|
152
|
+
return !isExportDeclaration(path.parentPath) && isCoupleLines(path);
|
|
156
153
|
}
|
|
157
154
|
|
|
158
155
|
function isFirst(path) {
|
|
@@ -33,8 +33,5 @@ module.exports.TSTypeLiteral = (path, {indent, traverse, write, maybe}) => {
|
|
|
33
33
|
function isNewline(path) {
|
|
34
34
|
const members = path.get('members');
|
|
35
35
|
|
|
36
|
-
|
|
37
|
-
return true;
|
|
38
|
-
|
|
39
|
-
return false;
|
|
36
|
+
return members.length && members[0].node.typeAnnotation;
|
|
40
37
|
}
|
package/package.json
CHANGED