@putout/printer 2.21.0 → 2.23.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/README.md +1 -0
- package/lib/tokenize/expressions/array-expression/new-line.js +2 -5
- package/lib/tokenize/expressions/assignment-expression.js +1 -4
- package/lib/tokenize/expressions/functions/function-declaration.js +1 -4
- package/lib/tokenize/expressions/functions/function-expression.js +1 -4
- package/lib/tokenize/expressions/functions/object-method.js +1 -0
- package/lib/tokenize/expressions/member-expressions/member-expressions.js +1 -4
- package/lib/tokenize/expressions/object-expression/object-property.js +1 -4
- package/lib/tokenize/expressions/object-pattern/max-properties-in-one-line.js +12 -0
- package/lib/tokenize/expressions/object-pattern/object-pattern.js +18 -8
- package/lib/tokenize/expressions/unary-expressions.js +2 -8
- package/lib/tokenize/literals/index.js +2 -8
- package/lib/tokenize/overrides.js +1 -0
- package/lib/tokenize/statements/break-statement.js +1 -4
- package/lib/tokenize/statements/export-declaration/export-declaration.js +2 -8
- package/lib/tokenize/statements/import-declaration/import-declaration.js +2 -8
- package/lib/tokenize/tokenize.js +1 -4
- package/lib/tokenize/typescript/ts-mapped-type.js +1 -4
- package/package.json +1 -1
package/ChangeLog
CHANGED
package/README.md
CHANGED
|
@@ -113,10 +113,7 @@ const isForOf = ({parentPath}) => parentPath.isForOfStatement();
|
|
|
113
113
|
const isStringAndString = ([a, b]) => isStringLiteral(a) && isStringLiteral(b);
|
|
114
114
|
|
|
115
115
|
const isShortTwoSimplesInsideCall = (path, short) => {
|
|
116
|
-
const {
|
|
117
|
-
node,
|
|
118
|
-
parentPath,
|
|
119
|
-
} = path;
|
|
116
|
+
const {node, parentPath} = path;
|
|
120
117
|
|
|
121
118
|
const {elements} = node;
|
|
122
119
|
const {length} = elements;
|
|
@@ -139,7 +136,7 @@ function isOneSimple(path) {
|
|
|
139
136
|
|
|
140
137
|
const [first] = elements;
|
|
141
138
|
|
|
142
|
-
if (first.isIdentifier() && first.node.name.length <
|
|
139
|
+
if (first.isIdentifier() && first.node.name.length < 15)
|
|
143
140
|
return true;
|
|
144
141
|
|
|
145
142
|
if (first.isStringLiteral() && first.node.value.length > 10)
|
|
@@ -6,10 +6,7 @@ const {printParams} = require('./params');
|
|
|
6
6
|
module.exports.FunctionExpression = (path, {print, maybe, write, traverse}) => {
|
|
7
7
|
const {node} = path;
|
|
8
8
|
|
|
9
|
-
const {
|
|
10
|
-
generator,
|
|
11
|
-
async,
|
|
12
|
-
} = node;
|
|
9
|
+
const {generator, async} = node;
|
|
13
10
|
|
|
14
11
|
maybe.write(async, 'async ');
|
|
15
12
|
write('function');
|
|
@@ -41,10 +41,7 @@ module.exports.MemberExpression = (path, {print, maybe, traverse}) => {
|
|
|
41
41
|
};
|
|
42
42
|
|
|
43
43
|
module.exports.OptionalMemberExpression = (path, {print, maybe}) => {
|
|
44
|
-
const {
|
|
45
|
-
computed,
|
|
46
|
-
optional,
|
|
47
|
-
} = path.node;
|
|
44
|
+
const {computed, optional} = path.node;
|
|
48
45
|
|
|
49
46
|
print('__object');
|
|
50
47
|
|
|
@@ -4,10 +4,7 @@ const {isConcatenation} = require('../binary-expression/concatanate');
|
|
|
4
4
|
const {isOneLine} = require('./object-expression');
|
|
5
5
|
|
|
6
6
|
module.exports.ObjectProperty = (path, {maybe, traverse, write}) => {
|
|
7
|
-
const {
|
|
8
|
-
shorthand,
|
|
9
|
-
computed,
|
|
10
|
-
} = path.node;
|
|
7
|
+
const {shorthand, computed} = path.node;
|
|
11
8
|
|
|
12
9
|
const key = path.get('key');
|
|
13
10
|
const value = path.get('value');
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
module.exports.checkMaxPropertiesInOneLine = (path, {maxPropertiesInOneLine}) => {
|
|
4
|
+
const {parentPath} = path;
|
|
5
|
+
|
|
6
|
+
if (parentPath.isObjectProperty())
|
|
7
|
+
return false;
|
|
8
|
+
|
|
9
|
+
const n = path.node.properties.length;
|
|
10
|
+
|
|
11
|
+
return maxPropertiesInOneLine >= n;
|
|
12
|
+
};
|
|
@@ -13,18 +13,25 @@ const {
|
|
|
13
13
|
exists,
|
|
14
14
|
} = require('../../is');
|
|
15
15
|
|
|
16
|
+
const {checkMaxPropertiesInOneLine} = require('./max-properties-in-one-line');
|
|
17
|
+
|
|
16
18
|
const isTwoLevelsDeep = ({parentPath}) => parentPath.parentPath.parentPath.isObjectProperty();
|
|
17
19
|
|
|
18
20
|
const isOneParentProperty = ({parentPath}) => parentPath.parentPath.node.properties?.length === 1;
|
|
19
21
|
|
|
20
22
|
module.exports.ObjectPattern = {
|
|
21
|
-
print(path, {indent, print, maybe}) {
|
|
23
|
+
print(path, {indent, print, maybe}, semantics) {
|
|
24
|
+
const {maxPropertiesInOneLine} = semantics;
|
|
22
25
|
indent.inc();
|
|
23
26
|
print('{');
|
|
24
27
|
|
|
25
28
|
const properties = path.get('properties');
|
|
26
29
|
const n = properties.length - 1;
|
|
27
|
-
|
|
30
|
+
|
|
31
|
+
const is = shouldAddNewline(path, {
|
|
32
|
+
maxPropertiesInOneLine,
|
|
33
|
+
});
|
|
34
|
+
|
|
28
35
|
const hasObject = n && hasObjectPattern(properties);
|
|
29
36
|
|
|
30
37
|
maybe.print.newline(is);
|
|
@@ -41,10 +48,7 @@ module.exports.ObjectPattern = {
|
|
|
41
48
|
const keyPath = property.get('key');
|
|
42
49
|
const isAssign = valuePath.isAssignmentPattern();
|
|
43
50
|
|
|
44
|
-
const {
|
|
45
|
-
shorthand,
|
|
46
|
-
computed,
|
|
47
|
-
} = property.node;
|
|
51
|
+
const {shorthand, computed} = property.node;
|
|
48
52
|
|
|
49
53
|
const couple = isCoupleLines(valuePath) && !exists(property.getPrevSibling()) && !path.parentPath.isObjectProperty();
|
|
50
54
|
|
|
@@ -120,13 +124,19 @@ function hasObjectPattern(properties) {
|
|
|
120
124
|
return false;
|
|
121
125
|
}
|
|
122
126
|
|
|
123
|
-
|
|
127
|
+
const ONE_LINE = false;
|
|
128
|
+
const COUPLE_LINES = true;
|
|
129
|
+
|
|
130
|
+
function shouldAddNewline(path, {maxPropertiesInOneLine}) {
|
|
124
131
|
const {parentPath} = path;
|
|
125
132
|
const properties = path.get('properties');
|
|
126
133
|
const n = properties.length - 1;
|
|
127
134
|
|
|
135
|
+
if (checkMaxPropertiesInOneLine(path, {maxPropertiesInOneLine}))
|
|
136
|
+
return ONE_LINE;
|
|
137
|
+
|
|
128
138
|
if (!isForOf(path) && !path.parentPath.isFunction() && n && checkLength(properties))
|
|
129
|
-
return
|
|
139
|
+
return COUPLE_LINES;
|
|
130
140
|
|
|
131
141
|
return parentPath.isObjectProperty();
|
|
132
142
|
}
|
|
@@ -1,9 +1,6 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
const {
|
|
4
|
-
isLast,
|
|
5
|
-
isNext,
|
|
6
|
-
} = require('../is');
|
|
3
|
+
const {isLast, isNext} = require('../is');
|
|
7
4
|
|
|
8
5
|
module.exports.UnaryExpression = unaryExpression;
|
|
9
6
|
module.exports.UpdateExpression = unaryExpression;
|
|
@@ -40,10 +37,7 @@ function printUnary(path, name, {print}) {
|
|
|
40
37
|
const isWord = (a) => /^(delete|typeof|void)$/.test(a);
|
|
41
38
|
|
|
42
39
|
function unaryExpression(path, {maybe, traverse}) {
|
|
43
|
-
const {
|
|
44
|
-
prefix,
|
|
45
|
-
operator,
|
|
46
|
-
} = path.node;
|
|
40
|
+
const {prefix, operator} = path.node;
|
|
47
41
|
|
|
48
42
|
const argPath = path.get('argument');
|
|
49
43
|
|
|
@@ -20,10 +20,7 @@ module.exports = {
|
|
|
20
20
|
write(path.node.value);
|
|
21
21
|
},
|
|
22
22
|
StringLiteral(path, {write}) {
|
|
23
|
-
const {
|
|
24
|
-
raw,
|
|
25
|
-
value,
|
|
26
|
-
} = path.node;
|
|
23
|
+
const {raw, value} = path.node;
|
|
27
24
|
|
|
28
25
|
write(raw || `'${value}'`);
|
|
29
26
|
},
|
|
@@ -31,10 +28,7 @@ module.exports = {
|
|
|
31
28
|
const {node} = path;
|
|
32
29
|
const parenthesized = node.extra?.parenthesized;
|
|
33
30
|
|
|
34
|
-
const {
|
|
35
|
-
name,
|
|
36
|
-
optional,
|
|
37
|
-
} = node;
|
|
31
|
+
const {name, optional} = node;
|
|
38
32
|
|
|
39
33
|
maybe.write(parenthesized, '(');
|
|
40
34
|
write(name);
|
|
@@ -7,10 +7,7 @@ const {
|
|
|
7
7
|
isLast,
|
|
8
8
|
} = require('../../is');
|
|
9
9
|
|
|
10
|
-
const {
|
|
11
|
-
markAfter,
|
|
12
|
-
isMarkedAfter,
|
|
13
|
-
} = require('../../mark');
|
|
10
|
+
const {markAfter, isMarkedAfter} = require('../../mark');
|
|
14
11
|
|
|
15
12
|
const {isExportNamespaceSpecifier} = require('@babel/types');
|
|
16
13
|
|
|
@@ -23,10 +20,7 @@ const options = {
|
|
|
23
20
|
};
|
|
24
21
|
|
|
25
22
|
module.exports.ExportSpecifier = (path, {print}) => {
|
|
26
|
-
const {
|
|
27
|
-
local,
|
|
28
|
-
exported,
|
|
29
|
-
} = path.node;
|
|
23
|
+
const {local, exported} = path.node;
|
|
30
24
|
|
|
31
25
|
print('__local');
|
|
32
26
|
|
|
@@ -2,10 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
const {markAfter} = require('../../mark');
|
|
4
4
|
|
|
5
|
-
const {
|
|
6
|
-
isLast,
|
|
7
|
-
isNext,
|
|
8
|
-
} = require('../../is');
|
|
5
|
+
const {isLast, isNext} = require('../../is');
|
|
9
6
|
|
|
10
7
|
const {parseImportSpecifiers} = require('parse-import-specifiers');
|
|
11
8
|
|
|
@@ -53,10 +50,7 @@ module.exports.ImportDeclaration = {
|
|
|
53
50
|
const last = index === importsCount;
|
|
54
51
|
const notLast = !last;
|
|
55
52
|
|
|
56
|
-
const {
|
|
57
|
-
imported,
|
|
58
|
-
local,
|
|
59
|
-
} = spec.node;
|
|
53
|
+
const {imported, local} = spec.node;
|
|
60
54
|
|
|
61
55
|
indent.inc();
|
|
62
56
|
|
package/lib/tokenize/tokenize.js
CHANGED
package/package.json
CHANGED