@putout/printer 1.92.4 → 1.93.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/lib/tokenize/expressions/object-pattern.js +59 -42
- package/package.json +1 -1
package/ChangeLog
CHANGED
|
@@ -8,55 +8,71 @@ const {
|
|
|
8
8
|
exists,
|
|
9
9
|
} = require('../is');
|
|
10
10
|
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
const is = shouldAddNewline(path);
|
|
18
|
-
|
|
19
|
-
maybe.print(is, '\n');
|
|
20
|
-
|
|
21
|
-
for (const [i, property] of properties.entries()) {
|
|
22
|
-
if (property.isRestElement()) {
|
|
23
|
-
print(property);
|
|
24
|
-
continue;
|
|
25
|
-
}
|
|
11
|
+
const isOneParentProperty = ({parentPath}) => parentPath.parentPath.node.properties.length === 1;
|
|
12
|
+
|
|
13
|
+
module.exports.ObjectPattern = {
|
|
14
|
+
print(path, {indent, print, maybe}) {
|
|
15
|
+
indent.inc();
|
|
16
|
+
print('{');
|
|
26
17
|
|
|
27
|
-
const
|
|
28
|
-
const
|
|
29
|
-
const
|
|
30
|
-
const {shorthand} = property.node;
|
|
31
|
-
const couple = isCoupleLines(valuePath) && !exists(property.getPrevSibling());
|
|
18
|
+
const properties = path.get('properties');
|
|
19
|
+
const n = properties.length - 1;
|
|
20
|
+
const is = shouldAddNewline(path);
|
|
32
21
|
|
|
33
|
-
maybe.
|
|
34
|
-
maybe.print.breakline(couple);
|
|
35
|
-
print(keyPath);
|
|
22
|
+
maybe.print(is, '\n');
|
|
36
23
|
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
24
|
+
for (const [i, property] of properties.entries()) {
|
|
25
|
+
if (property.isRestElement()) {
|
|
26
|
+
print(property);
|
|
27
|
+
continue;
|
|
28
|
+
}
|
|
42
29
|
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
print(',');
|
|
49
|
-
print.newline();
|
|
30
|
+
const valuePath = property.get('value');
|
|
31
|
+
const keyPath = property.get('key');
|
|
32
|
+
const isAssign = valuePath.isAssignmentPattern();
|
|
33
|
+
const {shorthand, computed} = property.node;
|
|
34
|
+
const couple = isCoupleLines(valuePath) && !exists(property.getPrevSibling());
|
|
50
35
|
|
|
51
|
-
|
|
36
|
+
maybe.indent(is);
|
|
37
|
+
maybe.print.breakline(couple);
|
|
38
|
+
|
|
39
|
+
maybe.print(computed, '[');
|
|
40
|
+
print(keyPath);
|
|
41
|
+
maybe.print(computed, ']');
|
|
42
|
+
|
|
43
|
+
if (!shorthand) {
|
|
44
|
+
print(': ');
|
|
45
|
+
print(valuePath);
|
|
46
|
+
} else if (isAssign) {
|
|
47
|
+
print(valuePath);
|
|
48
|
+
|
|
49
|
+
maybe.print(couple, ',');
|
|
50
|
+
maybe.print.newline(couple);
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
if (is) {
|
|
54
|
+
print(',');
|
|
55
|
+
print.newline();
|
|
56
|
+
|
|
57
|
+
continue;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
maybe.print(i < n, ', ');
|
|
52
61
|
}
|
|
53
62
|
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
63
|
+
indent.dec();
|
|
64
|
+
maybe.indent(is);
|
|
65
|
+
print('}');
|
|
66
|
+
},
|
|
67
|
+
afterIf(path) {
|
|
68
|
+
if (!path.parentPath.isObjectProperty())
|
|
69
|
+
return false;
|
|
70
|
+
|
|
71
|
+
return isOneParentProperty(path);
|
|
72
|
+
},
|
|
73
|
+
after(path, {print}) {
|
|
74
|
+
print.newline();
|
|
75
|
+
},
|
|
60
76
|
};
|
|
61
77
|
|
|
62
78
|
function checkLength(properties) {
|
|
@@ -85,3 +101,4 @@ function shouldAddNewline(path) {
|
|
|
85
101
|
|
|
86
102
|
return false;
|
|
87
103
|
}
|
|
104
|
+
|
package/package.json
CHANGED