@putout/printer 15.16.0 → 15.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 +10 -0
- package/lib/tokenize/expressions/assignment-expression/assignment-expression-comments.js +37 -0
- package/lib/tokenize/expressions/assignment-expression/assignment-expression.js +13 -0
- package/lib/tokenize/expressions/assignment-expression/maybe-write-brace.js +2 -1
- package/package.json +1 -1
package/ChangeLog
CHANGED
|
@@ -1,3 +1,13 @@
|
|
|
1
|
+
2025.08.04, v15.18.0
|
|
2
|
+
|
|
3
|
+
feature:
|
|
4
|
+
- 3357c63 @putout/printer: AssignmentExpression: leadingComments: CommentBlock
|
|
5
|
+
|
|
6
|
+
2025.08.04, v15.17.0
|
|
7
|
+
|
|
8
|
+
feature:
|
|
9
|
+
- da01c40 @putout/printer: AssignmentExpression: inside ReturnStatement with leadingComments (coderaiser/putout#235)
|
|
10
|
+
|
|
1
11
|
2025.08.01, v15.16.0
|
|
2
12
|
|
|
3
13
|
feature:
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const {types} = require('@putout/babel');
|
|
4
|
+
const {hasLeadingComment} = require('#is');
|
|
5
|
+
const {isReturnStatement} = types;
|
|
6
|
+
|
|
7
|
+
module.exports.printLeadingCommentLine = ({parentPath}) => !isReturnStatement(parentPath);
|
|
8
|
+
|
|
9
|
+
module.exports.maybeInsideReturnWithCommentStart = (path, {print, indent}) => {
|
|
10
|
+
const {parentPath} = path;
|
|
11
|
+
|
|
12
|
+
if (isReturnStatement(parentPath) && hasLeadingComment(path)) {
|
|
13
|
+
indent.inc();
|
|
14
|
+
const {leadingComments} = path.node;
|
|
15
|
+
|
|
16
|
+
print.breakline();
|
|
17
|
+
for (const {type, value} of leadingComments) {
|
|
18
|
+
if (type === 'CommentLine')
|
|
19
|
+
print(`//${value}`);
|
|
20
|
+
else
|
|
21
|
+
print(`/*${value}*/`);
|
|
22
|
+
|
|
23
|
+
print.breakline();
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
module.exports.maybeInsideReturnWithCommentEnd = (path, {print, indent}) => {
|
|
29
|
+
const {parentPath} = path;
|
|
30
|
+
|
|
31
|
+
if (!isReturnStatement(parentPath) || !hasLeadingComment(path))
|
|
32
|
+
return;
|
|
33
|
+
|
|
34
|
+
indent.dec();
|
|
35
|
+
print.breakline();
|
|
36
|
+
};
|
|
37
|
+
|
|
@@ -1,11 +1,18 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
3
|
const {types} = require('@putout/babel');
|
|
4
|
+
|
|
4
5
|
const {
|
|
5
6
|
maybePrintLeftBrace,
|
|
6
7
|
maybePrintRightBrace,
|
|
7
8
|
} = require('./maybe-write-brace');
|
|
8
9
|
|
|
10
|
+
const {
|
|
11
|
+
printLeadingCommentLine,
|
|
12
|
+
maybeInsideReturnWithCommentEnd,
|
|
13
|
+
maybeInsideReturnWithCommentStart,
|
|
14
|
+
} = require('./assignment-expression-comments');
|
|
15
|
+
|
|
9
16
|
const {
|
|
10
17
|
isExpressionStatement,
|
|
11
18
|
isAssignmentExpression,
|
|
@@ -18,6 +25,8 @@ module.exports.AssignmentExpression = (path, printer, semantics) => {
|
|
|
18
25
|
const {operator} = path.node;
|
|
19
26
|
|
|
20
27
|
maybePrintLeftBrace(path, printer, semantics);
|
|
28
|
+
maybeInsideReturnWithCommentStart(path, printer);
|
|
29
|
+
|
|
21
30
|
print('__left');
|
|
22
31
|
print.space();
|
|
23
32
|
print(operator);
|
|
@@ -34,9 +43,13 @@ module.exports.AssignmentExpression = (path, printer, semantics) => {
|
|
|
34
43
|
print.breakline();
|
|
35
44
|
}
|
|
36
45
|
|
|
46
|
+
maybeInsideReturnWithCommentEnd(path, printer);
|
|
47
|
+
|
|
37
48
|
maybePrintRightBrace(path, printer, semantics);
|
|
38
49
|
};
|
|
39
50
|
|
|
51
|
+
module.exports.AssignmentExpression.printLeadingCommentLine = printLeadingCommentLine;
|
|
52
|
+
|
|
40
53
|
function isMultiline(path) {
|
|
41
54
|
const {right} = path.node;
|
|
42
55
|
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
+
const {hasLeadingComment} = require('#is');
|
|
3
4
|
const {isParens} = require('../../maybe/maybe-parens');
|
|
4
5
|
|
|
5
6
|
module.exports.maybePrintLeftBrace = (path, printer, semantics) => {
|
|
@@ -40,7 +41,7 @@ function maybeWriteBrace(path, printer, semantics, {brace}) {
|
|
|
40
41
|
return;
|
|
41
42
|
}
|
|
42
43
|
|
|
43
|
-
if (!roundBraces.assign)
|
|
44
|
+
if (!roundBraces.assign && !hasLeadingComment(path))
|
|
44
45
|
return;
|
|
45
46
|
|
|
46
47
|
if (!isParens(path))
|
package/package.json
CHANGED