@putout/printer 2.21.0 → 2.22.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 +5 -0
- package/README.md +1 -0
- package/lib/tokenize/expressions/functions/object-method.js +1 -0
- package/lib/tokenize/expressions/object-pattern/max-properties-in-one-line.js +13 -0
- package/lib/tokenize/expressions/object-pattern/object-pattern.js +14 -4
- package/lib/tokenize/overrides.js +1 -0
- package/package.json +1 -1
package/ChangeLog
CHANGED
package/README.md
CHANGED
|
@@ -0,0 +1,13 @@
|
|
|
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
|
+
|
|
@@ -12,19 +12,23 @@ const {
|
|
|
12
12
|
isCoupleLines,
|
|
13
13
|
exists,
|
|
14
14
|
} = require('../../is');
|
|
15
|
+
const {checkMaxPropertiesInOneLine} = require('./max-properties-in-one-line');
|
|
15
16
|
|
|
16
17
|
const isTwoLevelsDeep = ({parentPath}) => parentPath.parentPath.parentPath.isObjectProperty();
|
|
17
18
|
|
|
18
19
|
const isOneParentProperty = ({parentPath}) => parentPath.parentPath.node.properties?.length === 1;
|
|
19
20
|
|
|
20
21
|
module.exports.ObjectPattern = {
|
|
21
|
-
print(path, {indent, print, maybe}) {
|
|
22
|
+
print(path, {indent, print, maybe}, semantics) {
|
|
23
|
+
const {maxPropertiesInOneLine} = semantics;
|
|
22
24
|
indent.inc();
|
|
23
25
|
print('{');
|
|
24
26
|
|
|
25
27
|
const properties = path.get('properties');
|
|
26
28
|
const n = properties.length - 1;
|
|
27
|
-
const is = shouldAddNewline(path
|
|
29
|
+
const is = shouldAddNewline(path, {
|
|
30
|
+
maxPropertiesInOneLine,
|
|
31
|
+
});
|
|
28
32
|
const hasObject = n && hasObjectPattern(properties);
|
|
29
33
|
|
|
30
34
|
maybe.print.newline(is);
|
|
@@ -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
|
}
|
package/package.json
CHANGED