@putout/printer 8.16.0 → 8.18.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
CHANGED
|
@@ -1,3 +1,13 @@
|
|
|
1
|
+
2024.04.19, v8.18.0
|
|
2
|
+
|
|
3
|
+
feature:
|
|
4
|
+
- 8a56e08 @putout/printer: ArrayExpression: SpreadElement after ObjectExpression
|
|
5
|
+
|
|
6
|
+
2024.04.16, v8.17.0
|
|
7
|
+
|
|
8
|
+
feature:
|
|
9
|
+
- 60c64ba @putout/printer: IfStatement: nested no body: improve
|
|
10
|
+
|
|
1
11
|
2024.04.16, v8.16.0
|
|
2
12
|
|
|
3
13
|
feature:
|
|
@@ -36,6 +36,16 @@ const isPrevObject = (a) => a.getPrevSibling().isObjectExpression();
|
|
|
36
36
|
const isObjectAfterSpread = (a) => isSpreadElement(a) && isNextObject(a) && !isPrevObject(a);
|
|
37
37
|
const isObjectAfterIdentifier = (a) => isIdentifier(a) && isNextObject(a) && !isPrevObject(a);
|
|
38
38
|
const isObjectAfterSimple = (a) => isObjectAfterSpread(a) || isObjectAfterIdentifier(a);
|
|
39
|
+
const isNextSpread = (a) => a.getNextSibling().isSpreadElement();
|
|
40
|
+
const isNextSpreadBetweenObjects = (a) => {
|
|
41
|
+
const next = a.getNextSibling();
|
|
42
|
+
const is = next.isSpreadElement();
|
|
43
|
+
|
|
44
|
+
if (!is)
|
|
45
|
+
return true;
|
|
46
|
+
|
|
47
|
+
return next.getNextSibling().isObjectExpression();
|
|
48
|
+
};
|
|
39
49
|
|
|
40
50
|
const isInsideOneElementArray = ({parentPath}) => parentPath.node.elements.length === 1;
|
|
41
51
|
|
|
@@ -85,6 +95,10 @@ module.exports.ArrayExpression = {
|
|
|
85
95
|
|
|
86
96
|
for (const [index, element] of elements.entries()) {
|
|
87
97
|
const is = isNewLine && isCurrentNewLine(element);
|
|
98
|
+
|
|
99
|
+
if (index && isSpreadElement(element) && !isNextSpread(element) && !isNextObject(element))
|
|
100
|
+
print.newline();
|
|
101
|
+
|
|
88
102
|
maybe.indent(is);
|
|
89
103
|
print(element);
|
|
90
104
|
|
|
@@ -96,7 +110,9 @@ module.exports.ArrayExpression = {
|
|
|
96
110
|
|
|
97
111
|
if (!is && index < n) {
|
|
98
112
|
print(',');
|
|
99
|
-
|
|
113
|
+
|
|
114
|
+
if (isNextSpreadBetweenObjects(element) || !(element.isObjectExpression() && isNextSpread(element)))
|
|
115
|
+
print.space();
|
|
100
116
|
}
|
|
101
117
|
}
|
|
102
118
|
|
|
@@ -116,7 +132,7 @@ module.exports.ArrayExpression = {
|
|
|
116
132
|
maybe.indent(elements.length && isNewLine);
|
|
117
133
|
}
|
|
118
134
|
|
|
119
|
-
if (isSimpleAndEmptyObject(elements)) {
|
|
135
|
+
if (isSimpleAndEmptyObject(elements) && !isSpreadElement(elements.at(-1))) {
|
|
120
136
|
print(',');
|
|
121
137
|
print.breakline();
|
|
122
138
|
}
|
|
@@ -67,11 +67,31 @@ module.exports.ExpressionStatement = {
|
|
|
67
67
|
if (hasTrailingComment(path) && !isCoupleLines(path))
|
|
68
68
|
return;
|
|
69
69
|
|
|
70
|
+
if (isTopParentLast(path))
|
|
71
|
+
return;
|
|
72
|
+
|
|
70
73
|
print.newline();
|
|
71
74
|
maybe.markAfter(store(), path);
|
|
72
75
|
},
|
|
73
76
|
};
|
|
74
77
|
|
|
78
|
+
function isTopParentLast({parentPath}) {
|
|
79
|
+
if (!parentPath.isIfStatement())
|
|
80
|
+
return false;
|
|
81
|
+
|
|
82
|
+
const nextParent = parentPath.parentPath;
|
|
83
|
+
|
|
84
|
+
if (!nextParent.isIfStatement())
|
|
85
|
+
return false;
|
|
86
|
+
|
|
87
|
+
const nextNext = nextParent.parentPath;
|
|
88
|
+
|
|
89
|
+
if (!nextNext.isIfStatement())
|
|
90
|
+
return false;
|
|
91
|
+
|
|
92
|
+
return isLast(nextNext);
|
|
93
|
+
}
|
|
94
|
+
|
|
75
95
|
function isNotLastBody(path) {
|
|
76
96
|
return path.parentPath.get('body') === path;
|
|
77
97
|
}
|
|
@@ -56,7 +56,12 @@ module.exports.IfStatement = {
|
|
|
56
56
|
write.space();
|
|
57
57
|
traverse(alternate);
|
|
58
58
|
} else if (alternate.isIfStatement()) {
|
|
59
|
-
|
|
59
|
+
if (alternate.get('consequent').isBlockStatement())
|
|
60
|
+
write.space();
|
|
61
|
+
else
|
|
62
|
+
indent();
|
|
63
|
+
|
|
64
|
+
write('else ');
|
|
60
65
|
traverse(alternate);
|
|
61
66
|
} else if (exists(alternate)) {
|
|
62
67
|
maybe.write.newline(isVar);
|
|
@@ -69,6 +74,9 @@ module.exports.IfStatement = {
|
|
|
69
74
|
indent.dec();
|
|
70
75
|
}
|
|
71
76
|
|
|
77
|
+
if (!isNext(path) && !consequent.isBlockStatement())
|
|
78
|
+
return;
|
|
79
|
+
|
|
72
80
|
if (path === partOfAlternate && isInside(path))
|
|
73
81
|
print.newline();
|
|
74
82
|
},
|
package/package.json
CHANGED