@putout/printer 1.40.0 → 1.40.2
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 +11 -4
- package/lib/tokenize/statements/block-statement.js +18 -0
- package/package.json +1 -1
package/ChangeLog
CHANGED
|
@@ -1,3 +1,13 @@
|
|
|
1
|
+
2023.04.13, v1.40.2
|
|
2
|
+
|
|
3
|
+
feature:
|
|
4
|
+
- 6d8d812 @putout/printer: comments: newline after CommentLine
|
|
5
|
+
|
|
6
|
+
2023.04.13, v1.40.1
|
|
7
|
+
|
|
8
|
+
fix:
|
|
9
|
+
- e868511 @putout/printer: drop newline after BlockStatement when parentPath is IfStatement and current path not alternate
|
|
10
|
+
|
|
1
11
|
2023.04.13, v1.40.0
|
|
2
12
|
|
|
3
13
|
feature:
|
package/lib/tokenize/comments.js
CHANGED
|
@@ -45,7 +45,7 @@ module.exports.parseLeadingComments = (path, {print, maybe}) => {
|
|
|
45
45
|
}
|
|
46
46
|
};
|
|
47
47
|
|
|
48
|
-
module.exports.parseTrailingComments = (path, {
|
|
48
|
+
module.exports.parseTrailingComments = (path, {write, maybe}) => {
|
|
49
49
|
const {trailingComments} = path.node;
|
|
50
50
|
|
|
51
51
|
if (!trailingComments || !trailingComments.length)
|
|
@@ -54,10 +54,13 @@ module.exports.parseTrailingComments = (path, {print}) => {
|
|
|
54
54
|
if (isNext(path))
|
|
55
55
|
return;
|
|
56
56
|
|
|
57
|
-
for (const {type, value} of trailingComments) {
|
|
57
|
+
for (const {type, value, loc} of trailingComments) {
|
|
58
58
|
if (type === 'CommentLine') {
|
|
59
|
-
|
|
60
|
-
|
|
59
|
+
const sameLine = isSameLine(path, loc);
|
|
60
|
+
maybe.write.space(sameLine);
|
|
61
|
+
maybe.indent(!sameLine);
|
|
62
|
+
write(`//${value}`);
|
|
63
|
+
maybe.write.newline(!sameLine);
|
|
61
64
|
|
|
62
65
|
continue;
|
|
63
66
|
}
|
|
@@ -67,3 +70,7 @@ module.exports.parseTrailingComments = (path, {print}) => {
|
|
|
67
70
|
function shouldAddNewlineBefore(path) {
|
|
68
71
|
return path.isStatement() && !isFirst(path) && !hasPrevNewline(path);
|
|
69
72
|
}
|
|
73
|
+
|
|
74
|
+
function isSameLine(path, loc) {
|
|
75
|
+
return path.node.loc.start.line === loc.start.line;
|
|
76
|
+
}
|
|
@@ -4,6 +4,7 @@ const {
|
|
|
4
4
|
isNext,
|
|
5
5
|
isParentProgram,
|
|
6
6
|
isLast,
|
|
7
|
+
exists,
|
|
7
8
|
} = require('../is');
|
|
8
9
|
|
|
9
10
|
const isFirstStatement = (path) => path.get('body.0')?.isStatement();
|
|
@@ -56,9 +57,26 @@ function shouldAddNewlineAfter(path) {
|
|
|
56
57
|
if (isLast(path))
|
|
57
58
|
return false;
|
|
58
59
|
|
|
60
|
+
if (isNextIfAlternate(path))
|
|
61
|
+
return false;
|
|
62
|
+
|
|
59
63
|
return true;
|
|
60
64
|
}
|
|
61
65
|
|
|
66
|
+
function isNextIfAlternate(path) {
|
|
67
|
+
const {parentPath} = path;
|
|
68
|
+
|
|
69
|
+
if (!parentPath.isIfStatement())
|
|
70
|
+
return false;
|
|
71
|
+
|
|
72
|
+
const alternate = parentPath.get('alternate');
|
|
73
|
+
|
|
74
|
+
if (path === alternate)
|
|
75
|
+
return false;
|
|
76
|
+
|
|
77
|
+
return exists(alternate);
|
|
78
|
+
}
|
|
79
|
+
|
|
62
80
|
function isTry({parentPath}) {
|
|
63
81
|
if (parentPath.isTryStatement())
|
|
64
82
|
return true;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@putout/printer",
|
|
3
|
-
"version": "1.40.
|
|
3
|
+
"version": "1.40.2",
|
|
4
4
|
"type": "commonjs",
|
|
5
5
|
"author": "coderaiser <mnemonic.enemy@gmail.com> (https://github.com/coderaiser)",
|
|
6
6
|
"description": "Easiest possible opinionated Babel AST printer made with ❤️ to use in 🐊Putout",
|