@putout/printer 1.88.0 → 1.90.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,16 @@
|
|
|
1
|
+
2023.05.10, v1.90.0
|
|
2
|
+
|
|
3
|
+
feature:
|
|
4
|
+
- 5cd1dcc @putout/printer: add support of comments inside BlockStatement
|
|
5
|
+
|
|
6
|
+
2023.05.09, v1.89.0
|
|
7
|
+
|
|
8
|
+
fix:
|
|
9
|
+
- 17bae21 @putout/printer: rm useless condition
|
|
10
|
+
|
|
11
|
+
feature:
|
|
12
|
+
- bf25bda @putout/printer: ForOfStatement: newline
|
|
13
|
+
|
|
1
14
|
2023.05.09, v1.88.0
|
|
2
15
|
|
|
3
16
|
feature:
|
package/lib/tokenize/comments.js
CHANGED
|
@@ -80,6 +80,22 @@ module.exports.parseTrailingComments = (path, {write, maybe}, format) => {
|
|
|
80
80
|
}
|
|
81
81
|
};
|
|
82
82
|
|
|
83
|
+
module.exports.parseComments = (path, {write}) => {
|
|
84
|
+
const {comments} = path.node;
|
|
85
|
+
|
|
86
|
+
if (!comments)
|
|
87
|
+
return;
|
|
88
|
+
|
|
89
|
+
for (const {type, value} of path.node.comments) {
|
|
90
|
+
if (type === 'CommentLine') {
|
|
91
|
+
write.breakline();
|
|
92
|
+
write('//');
|
|
93
|
+
write(value);
|
|
94
|
+
write.newline();
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
};
|
|
98
|
+
|
|
83
99
|
function isSameLine(path, loc) {
|
|
84
100
|
return path.node.loc.start.line === loc.start.line;
|
|
85
101
|
}
|
|
@@ -13,12 +13,13 @@ const {
|
|
|
13
13
|
} = require('@babel/types');
|
|
14
14
|
|
|
15
15
|
const {markAfter} = require('../mark');
|
|
16
|
+
const {parseComments} = require('../comments');
|
|
16
17
|
|
|
17
18
|
const isFirstStatement = (path) => path.get('body.0')?.isStatement();
|
|
18
19
|
const isMethodOrArrow = (path) => isArrowFunctionExpression(path) || isObjectMethod(path);
|
|
19
20
|
|
|
20
21
|
module.exports.BlockStatement = {
|
|
21
|
-
print(path, {indent, maybe, print}) {
|
|
22
|
+
print(path, {indent, maybe, print, write}) {
|
|
22
23
|
const body = path.get('body');
|
|
23
24
|
|
|
24
25
|
if (path.parentPath.isBlockStatement())
|
|
@@ -27,13 +28,15 @@ module.exports.BlockStatement = {
|
|
|
27
28
|
indent.inc();
|
|
28
29
|
print('{');
|
|
29
30
|
|
|
30
|
-
if (
|
|
31
|
+
if (isFirstStatement(path))
|
|
31
32
|
print.newline();
|
|
32
33
|
|
|
33
34
|
for (const element of body) {
|
|
34
35
|
print(element);
|
|
35
36
|
}
|
|
36
37
|
|
|
38
|
+
parseComments(path, {write});
|
|
39
|
+
|
|
37
40
|
indent.dec();
|
|
38
41
|
maybe.indent(body.length);
|
|
39
42
|
print('}');
|
|
@@ -98,3 +101,4 @@ function isTry({parentPath}) {
|
|
|
98
101
|
|
|
99
102
|
return false;
|
|
100
103
|
}
|
|
104
|
+
|
|
@@ -10,6 +10,7 @@ const {
|
|
|
10
10
|
const {
|
|
11
11
|
isFirst,
|
|
12
12
|
isNext,
|
|
13
|
+
isLast,
|
|
13
14
|
} = require('../is');
|
|
14
15
|
|
|
15
16
|
module.exports.ForOfStatement = {
|
|
@@ -34,6 +35,9 @@ module.exports.ForOfStatement = {
|
|
|
34
35
|
print(' ');
|
|
35
36
|
print('__body');
|
|
36
37
|
|
|
38
|
+
const {length} = bodyPath.node.body;
|
|
39
|
+
maybe.print.newline(!length && !isLast(path) && !isNext(path));
|
|
40
|
+
|
|
37
41
|
return;
|
|
38
42
|
}
|
|
39
43
|
|
|
@@ -44,7 +48,12 @@ module.exports.ForOfStatement = {
|
|
|
44
48
|
|
|
45
49
|
maybe.markAfter(isMarkedAfter(bodyPath), path);
|
|
46
50
|
},
|
|
47
|
-
afterIf:
|
|
51
|
+
afterIf: (path) => {
|
|
52
|
+
if (isNext(path))
|
|
53
|
+
return true;
|
|
54
|
+
|
|
55
|
+
return false;
|
|
56
|
+
},
|
|
48
57
|
after(path, {print}) {
|
|
49
58
|
print.linebreak();
|
|
50
59
|
markAfter(path);
|
package/package.json
CHANGED