@putout/printer 2.12.0 → 2.13.1
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/README.md +2 -6
- package/lib/tokenize/expressions/array-expression/array-expression.js +1 -4
- package/lib/tokenize/expressions/array-expression/new-line.js +9 -14
- 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/is.js +0 -1
- 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
package/README.md
CHANGED
|
@@ -35,9 +35,7 @@ And update `.putout.json`:
|
|
|
35
35
|
```json
|
|
36
36
|
{
|
|
37
37
|
"printer": "putout",
|
|
38
|
-
"plugins": [
|
|
39
|
-
"printer"
|
|
40
|
-
]
|
|
38
|
+
"plugins": ["printer"]
|
|
41
39
|
}
|
|
42
40
|
```
|
|
43
41
|
|
|
@@ -268,9 +266,7 @@ function speed(printer) {
|
|
|
268
266
|
for (let i = 0; i < 1000; i++) {
|
|
269
267
|
putout(code, {
|
|
270
268
|
printer,
|
|
271
|
-
plugins: [
|
|
272
|
-
'remove-unused-variables',
|
|
273
|
-
],
|
|
269
|
+
plugins: ['remove-unused-variables'],
|
|
274
270
|
});
|
|
275
271
|
}
|
|
276
272
|
|
|
@@ -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 = {
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
3
|
const {isSimple} = require('@putout/operate');
|
|
4
|
+
|
|
4
5
|
const {
|
|
5
6
|
isObjectExpression,
|
|
6
7
|
isArrayExpression,
|
|
@@ -10,8 +11,8 @@ const {
|
|
|
10
11
|
isBooleanLiteral,
|
|
11
12
|
isNullLiteral,
|
|
12
13
|
isStringLiteral,
|
|
13
|
-
|
|
14
14
|
} = require('@babel/types');
|
|
15
|
+
|
|
15
16
|
const {
|
|
16
17
|
isStringAndMember,
|
|
17
18
|
isStringAndIdentifier,
|
|
@@ -19,7 +20,6 @@ const {
|
|
|
19
20
|
isCoupleLines,
|
|
20
21
|
isStringAndArray,
|
|
21
22
|
isIdentifierAndIdentifier,
|
|
22
|
-
|
|
23
23
|
} = require('../../is');
|
|
24
24
|
|
|
25
25
|
const {round} = Math;
|
|
@@ -129,6 +129,9 @@ function isOneSimple(path) {
|
|
|
129
129
|
if (first.isIdentifier() && first.node.name.length < 5)
|
|
130
130
|
return true;
|
|
131
131
|
|
|
132
|
+
if (first.isStringLiteral() && first.node.value.length > 10)
|
|
133
|
+
return false;
|
|
134
|
+
|
|
132
135
|
if (!first.isIdentifier() && isSimple(first))
|
|
133
136
|
return true;
|
|
134
137
|
|
|
@@ -154,10 +157,7 @@ function isTwoStringsDifferentLength(strings) {
|
|
|
154
157
|
}
|
|
155
158
|
|
|
156
159
|
function isInsideLoop(path) {
|
|
157
|
-
|
|
158
|
-
return false;
|
|
159
|
-
|
|
160
|
-
return true;
|
|
160
|
+
return path.parentPath.isForOfStatement();
|
|
161
161
|
}
|
|
162
162
|
|
|
163
163
|
function tooLong(path) {
|
|
@@ -202,6 +202,7 @@ function isLastArg({parentPath}) {
|
|
|
202
202
|
function isParentProperty(path) {
|
|
203
203
|
return path.find(isObjectProperty);
|
|
204
204
|
}
|
|
205
|
+
|
|
205
206
|
module.exports.isIncreaseIndent = isIncreaseIndent;
|
|
206
207
|
function isIncreaseIndent(path) {
|
|
207
208
|
const elements = path.get('elements');
|
|
@@ -215,20 +216,14 @@ function isIncreaseIndent(path) {
|
|
|
215
216
|
if (elements[0].isObjectExpression())
|
|
216
217
|
return true;
|
|
217
218
|
|
|
218
|
-
|
|
219
|
-
return true;
|
|
220
|
-
|
|
221
|
-
return false;
|
|
219
|
+
return isStringAndObject(elements);
|
|
222
220
|
}
|
|
223
221
|
|
|
224
222
|
function isInsideCallLoop(path) {
|
|
225
223
|
if (!path.parentPath.isCallExpression())
|
|
226
224
|
return false;
|
|
227
225
|
|
|
228
|
-
|
|
229
|
-
return false;
|
|
230
|
-
|
|
231
|
-
return true;
|
|
226
|
+
return path.parentPath.parentPath.isForOfStatement();
|
|
232
227
|
}
|
|
233
228
|
|
|
234
229
|
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
|
}
|
package/lib/tokenize/is.js
CHANGED
|
@@ -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