@putout/printer 1.70.2 → 1.70.4
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/lib/tokenize/comments.js +21 -8
- package/lib/tokenize/expressions/object-expression.js +6 -2
- package/lib/tokenize/is.js +3 -1
- package/lib/tokenize/statements/export-declarations.js +3 -2
- package/lib/tokenize/statements/expression-statement.js +2 -2
- package/lib/tokenize/statements/variable-declaration.js +2 -2
- package/package.json +1 -1
package/ChangeLog
CHANGED
package/lib/tokenize/comments.js
CHANGED
|
@@ -4,28 +4,30 @@ const {isNext} = require('./is');
|
|
|
4
4
|
|
|
5
5
|
const {markBefore} = require('./mark');
|
|
6
6
|
|
|
7
|
-
module.exports.parseLeadingComments = (path, {print, maybe}) => {
|
|
7
|
+
module.exports.parseLeadingComments = (path, {print, maybe, indent}) => {
|
|
8
8
|
const {leadingComments} = path.node;
|
|
9
9
|
|
|
10
10
|
if (!leadingComments || !leadingComments.length)
|
|
11
11
|
return;
|
|
12
12
|
|
|
13
13
|
const insideFn = path.parentPath.isFunction();
|
|
14
|
-
const
|
|
14
|
+
const isProperty = path.isObjectProperty();
|
|
15
|
+
const isIndent = !path.isClassMethod() && !insideFn && !isProperty;
|
|
15
16
|
|
|
16
17
|
for (const {type, value} of leadingComments) {
|
|
17
18
|
maybe.indent(isIndent);
|
|
18
19
|
|
|
19
20
|
if (type === 'CommentLine') {
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
maybe.indent.dec(insideFn);
|
|
21
|
+
maybeInsideFn(insideFn, {
|
|
22
|
+
print,
|
|
23
|
+
indent,
|
|
24
|
+
});
|
|
25
25
|
|
|
26
|
+
maybe.print.space(isProperty);
|
|
26
27
|
print(`//${value}`);
|
|
27
|
-
print.newline();
|
|
28
28
|
|
|
29
|
+
maybe.print.breakline(isProperty);
|
|
30
|
+
maybe.print.newline(!isProperty);
|
|
29
31
|
continue;
|
|
30
32
|
}
|
|
31
33
|
|
|
@@ -67,3 +69,14 @@ module.exports.parseTrailingComments = (path, {write, maybe}) => {
|
|
|
67
69
|
function isSameLine(path, loc) {
|
|
68
70
|
return path.node.loc.start.line === loc.start.line;
|
|
69
71
|
}
|
|
72
|
+
|
|
73
|
+
function maybeInsideFn(insideFn, {print, indent}) {
|
|
74
|
+
if (!insideFn)
|
|
75
|
+
return;
|
|
76
|
+
|
|
77
|
+
indent.inc();
|
|
78
|
+
indent.inc();
|
|
79
|
+
print.breakline();
|
|
80
|
+
indent.dec();
|
|
81
|
+
indent.dec();
|
|
82
|
+
}
|
|
@@ -5,6 +5,9 @@ const {
|
|
|
5
5
|
isForOf,
|
|
6
6
|
isIf,
|
|
7
7
|
noTrailingComment,
|
|
8
|
+
isNewlineBetweenSiblings,
|
|
9
|
+
noLeadingComment,
|
|
10
|
+
noComment,
|
|
8
11
|
} = require('../is');
|
|
9
12
|
|
|
10
13
|
const {isFunction} = require('@babel/types');
|
|
@@ -41,7 +44,7 @@ module.exports.ObjectExpression = (path, {print, maybe, indent}) => {
|
|
|
41
44
|
continue;
|
|
42
45
|
}
|
|
43
46
|
|
|
44
|
-
maybe.indent(manyLines);
|
|
47
|
+
maybe.indent(manyLines && noLeadingComment(property));
|
|
45
48
|
|
|
46
49
|
if (property.isObjectMethod()) {
|
|
47
50
|
print(property);
|
|
@@ -49,7 +52,8 @@ module.exports.ObjectExpression = (path, {print, maybe, indent}) => {
|
|
|
49
52
|
}
|
|
50
53
|
|
|
51
54
|
print(property);
|
|
52
|
-
maybe.print.newline(manyLines && noTrailingComment(property));
|
|
55
|
+
maybe.print.newline(manyLines && noTrailingComment(property) && noComment(property));
|
|
56
|
+
maybe.print.linebreak(isNewlineBetweenSiblings(property));
|
|
53
57
|
}
|
|
54
58
|
|
|
55
59
|
indent.dec();
|
package/lib/tokenize/is.js
CHANGED
|
@@ -68,7 +68,7 @@ module.exports.isForOf = (path) => {
|
|
|
68
68
|
return false;
|
|
69
69
|
};
|
|
70
70
|
|
|
71
|
-
module.exports.
|
|
71
|
+
module.exports.isNewlineBetweenSiblings = (path) => {
|
|
72
72
|
const endCurrent = path.node?.loc?.end?.line;
|
|
73
73
|
const startNext = path.getNextSibling().node?.loc?.start?.line;
|
|
74
74
|
|
|
@@ -87,3 +87,5 @@ module.exports.satisfy = (conditions) => (path) => {
|
|
|
87
87
|
};
|
|
88
88
|
|
|
89
89
|
module.exports.noTrailingComment = (path) => !path.node.trailingComments?.length;
|
|
90
|
+
module.exports.noComment = (path) => !path.node.comments?.length;
|
|
91
|
+
module.exports.noLeadingComment = (path) => !path.node.leadingComments?.length;
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
const {
|
|
3
|
+
const {isNewlineBetweenSiblings} = require('../is');
|
|
4
|
+
|
|
4
5
|
const {
|
|
5
6
|
markAfter,
|
|
6
7
|
isMarkedAfter,
|
|
@@ -66,7 +67,7 @@ module.exports.ExportNamedDeclaration = {
|
|
|
66
67
|
if (isDeclarationNewline(path))
|
|
67
68
|
return false;
|
|
68
69
|
|
|
69
|
-
return
|
|
70
|
+
return isNewlineBetweenSiblings(path);
|
|
70
71
|
},
|
|
71
72
|
after(path, {print}) {
|
|
72
73
|
print.newline();
|
|
@@ -5,12 +5,12 @@ const {
|
|
|
5
5
|
isLast,
|
|
6
6
|
isParentBlock,
|
|
7
7
|
isParentLast,
|
|
8
|
-
|
|
8
|
+
isNewlineBetweenSiblings,
|
|
9
9
|
satisfy,
|
|
10
10
|
} = require('../is');
|
|
11
11
|
|
|
12
12
|
const shouldBreakline = satisfy([
|
|
13
|
-
|
|
13
|
+
isNewlineBetweenSiblings,
|
|
14
14
|
isNotLastBody,
|
|
15
15
|
isStrictMode,
|
|
16
16
|
]);
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
const {
|
|
4
4
|
isNext,
|
|
5
5
|
isCoupleLines,
|
|
6
|
-
|
|
6
|
+
isNewlineBetweenSiblings,
|
|
7
7
|
} = require('../is');
|
|
8
8
|
|
|
9
9
|
const {hasPrevNewline} = require('../mark');
|
|
@@ -42,7 +42,7 @@ module.exports.VariableDeclaration = {
|
|
|
42
42
|
isNextAssign,
|
|
43
43
|
isNextCoupleLines,
|
|
44
44
|
notLastPrevVarNotNextVar,
|
|
45
|
-
|
|
45
|
+
isNewlineBetweenSiblings,
|
|
46
46
|
notLastParentExport,
|
|
47
47
|
],
|
|
48
48
|
after(path, {maybe, store}) {
|
package/package.json
CHANGED