@putout/printer 1.75.0 → 1.76.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/call-expression.js +1 -2
- package/lib/tokenize/expressions/class.js +3 -1
- package/lib/tokenize/expressions/object-expression.js +16 -3
- package/lib/tokenize/is.js +1 -1
- package/lib/tokenize/jsx/jsx-text.js +2 -4
- package/lib/tokenize/statements/expression-statement.js +30 -8
- package/lib/tokenize/statements/for-in-statement.js +3 -1
- package/lib/tokenize/statements/import-declaration.js +3 -1
- package/lib/tokenize/statements/switch-statement.js +3 -1
- package/lib/tokenize/statements/variable-declaration.js +3 -1
- package/package.json +1 -1
package/ChangeLog
CHANGED
|
@@ -7,7 +7,8 @@ const {
|
|
|
7
7
|
noTrailingComment,
|
|
8
8
|
isNewlineBetweenSiblings,
|
|
9
9
|
noLeadingComment,
|
|
10
|
-
|
|
10
|
+
hasLeadingComment,
|
|
11
|
+
exists,
|
|
11
12
|
} = require('../is');
|
|
12
13
|
|
|
13
14
|
const {isFunction} = require('@babel/types');
|
|
@@ -52,8 +53,11 @@ module.exports.ObjectExpression = (path, {print, maybe, indent}) => {
|
|
|
52
53
|
}
|
|
53
54
|
|
|
54
55
|
print(property);
|
|
55
|
-
|
|
56
|
-
|
|
56
|
+
|
|
57
|
+
if (!hasNextLeadingComment(property)) {
|
|
58
|
+
maybe.print.newline(manyLines && noTrailingComment(property));
|
|
59
|
+
maybe.print.linebreak(isNewlineBetweenSiblings(property));
|
|
60
|
+
}
|
|
57
61
|
}
|
|
58
62
|
|
|
59
63
|
indent.dec();
|
|
@@ -63,6 +67,15 @@ module.exports.ObjectExpression = (path, {print, maybe, indent}) => {
|
|
|
63
67
|
maybe.print(parens, ')');
|
|
64
68
|
};
|
|
65
69
|
|
|
70
|
+
const hasNextLeadingComment = (path) => {
|
|
71
|
+
const next = path.getNextSibling();
|
|
72
|
+
|
|
73
|
+
if (!exists(next))
|
|
74
|
+
return false;
|
|
75
|
+
|
|
76
|
+
return hasLeadingComment(next);
|
|
77
|
+
};
|
|
78
|
+
|
|
66
79
|
function shouldAddNewline(path) {
|
|
67
80
|
if (!path.parentPath.isLogicalExpression())
|
|
68
81
|
return false;
|
package/lib/tokenize/is.js
CHANGED
|
@@ -85,7 +85,7 @@ module.exports.satisfy = (conditions) => (path) => {
|
|
|
85
85
|
};
|
|
86
86
|
|
|
87
87
|
module.exports.hasTrailingComment = (path) => path.node?.trailingComments?.length;
|
|
88
|
+
module.exports.hasLeadingComment = (path) => path.node?.leadingComments?.length;
|
|
88
89
|
|
|
89
90
|
module.exports.noTrailingComment = (path) => !path.node.trailingComments?.length;
|
|
90
|
-
module.exports.noComment = (path) => !path.node.comments?.length;
|
|
91
91
|
module.exports.noLeadingComment = (path) => !path.node.leadingComments?.length;
|
|
@@ -9,16 +9,14 @@ module.exports.JSXText = (path, {write, indent}) => {
|
|
|
9
9
|
|
|
10
10
|
if (isSpacesOnly && hasNext) {
|
|
11
11
|
indent.inc();
|
|
12
|
-
write.
|
|
13
|
-
write.indent();
|
|
12
|
+
write.breakline();
|
|
14
13
|
indent.dec();
|
|
15
14
|
|
|
16
15
|
return;
|
|
17
16
|
}
|
|
18
17
|
|
|
19
18
|
if (isSpacesOnly) {
|
|
20
|
-
write.
|
|
21
|
-
write.indent();
|
|
19
|
+
write.breakline();
|
|
22
20
|
|
|
23
21
|
return;
|
|
24
22
|
}
|
|
@@ -9,15 +9,30 @@ const {
|
|
|
9
9
|
satisfy,
|
|
10
10
|
noTrailingComment,
|
|
11
11
|
hasTrailingComment,
|
|
12
|
+
exists,
|
|
12
13
|
} = require('../is');
|
|
13
14
|
|
|
15
|
+
const satisfyAfter = satisfy([
|
|
16
|
+
isParentBlockOrNotLastOrParentLast,
|
|
17
|
+
isParentBlock,
|
|
18
|
+
isNext,
|
|
19
|
+
isNextUp,
|
|
20
|
+
]);
|
|
21
|
+
|
|
14
22
|
const isNextLiteral = (path) => {
|
|
15
23
|
const next = path.getNextSibling();
|
|
24
|
+
|
|
25
|
+
if (!exists(next))
|
|
26
|
+
return false;
|
|
27
|
+
|
|
16
28
|
const expression = next.get('expression');
|
|
17
29
|
|
|
18
30
|
if (expression.isTemplateLiteral())
|
|
19
31
|
return true;
|
|
20
32
|
|
|
33
|
+
if (expression.isArrayExpression())
|
|
34
|
+
return true;
|
|
35
|
+
|
|
21
36
|
return expression.isLiteral();
|
|
22
37
|
};
|
|
23
38
|
|
|
@@ -39,15 +54,22 @@ module.exports.ExpressionStatement = {
|
|
|
39
54
|
store(true);
|
|
40
55
|
}
|
|
41
56
|
},
|
|
42
|
-
|
|
43
|
-
isParentBlockOrNotLastOrParentLast,
|
|
44
|
-
isParentBlock,
|
|
45
|
-
isNext,
|
|
46
|
-
isNextUp,
|
|
47
|
-
],
|
|
48
|
-
after(path, {print, maybe, store}) {
|
|
57
|
+
afterIf: (path) => {
|
|
49
58
|
if (hasTrailingComment(path) && isNextLiteral(path))
|
|
50
|
-
return;
|
|
59
|
+
return false;
|
|
60
|
+
|
|
61
|
+
if (satisfyAfter(path))
|
|
62
|
+
return true;
|
|
63
|
+
|
|
64
|
+
if (hasTrailingComment(path) && isLast(path))
|
|
65
|
+
return true;
|
|
66
|
+
|
|
67
|
+
return false;
|
|
68
|
+
},
|
|
69
|
+
after(path, {print, maybe, store}) {
|
|
70
|
+
if (hasTrailingComment(path) && isLast(path)) {
|
|
71
|
+
print.breakline();
|
|
72
|
+
}
|
|
51
73
|
|
|
52
74
|
print.newline();
|
|
53
75
|
maybe.markAfter(store(), path);
|
|
@@ -20,7 +20,9 @@ module.exports.SwitchStatement = {
|
|
|
20
20
|
print(switchCase.get('test'));
|
|
21
21
|
print(':');
|
|
22
22
|
|
|
23
|
-
const isBlock = switchCase
|
|
23
|
+
const isBlock = switchCase
|
|
24
|
+
.get('consequent.0')
|
|
25
|
+
.isBlockStatement();
|
|
24
26
|
|
|
25
27
|
maybe.indent.inc(!isBlock);
|
|
26
28
|
maybe.print.newline(!isBlock);
|
|
@@ -125,5 +125,7 @@ const isNextAssign = (path) => {
|
|
|
125
125
|
if (parentPath.isBlockStatement() && parentPath.node.body.length < 3)
|
|
126
126
|
return false;
|
|
127
127
|
|
|
128
|
-
return nextPath
|
|
128
|
+
return nextPath
|
|
129
|
+
.get('expression')
|
|
130
|
+
.isAssignmentExpression();
|
|
129
131
|
};
|
package/package.json
CHANGED