@putout/printer 15.18.1 → 15.19.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 +26 -4
- package/lib/tokenize/expressions/assignment-expression/assignment-expression.js +2 -0
- package/lib/tokenize/expressions/assignment-expression/maybe-parens-condition.js +1 -0
- package/lib/tokenize/expressions/sequence-expression/maybe-write-brace.js +9 -31
- package/lib/tokenize/expressions/sequence-expression/sequence-expression-comments.js +22 -0
- package/lib/tokenize/expressions/sequence-expression/sequence-expression.js +49 -19
- package/package.json +1 -1
package/ChangeLog
CHANGED
|
@@ -1,3 +1,13 @@
|
|
|
1
|
+
2025.08.05, v15.19.0
|
|
2
|
+
|
|
3
|
+
feature:
|
|
4
|
+
- f518cd6 @putout/printer: SequenceExpression: leadingComments inside AssignmentExpressions: improve
|
|
5
|
+
|
|
6
|
+
2025.08.05, v15.18.2
|
|
7
|
+
|
|
8
|
+
feature:
|
|
9
|
+
- a7fd7cc @putout/printer: AssignmentExpression: comments: inside SequenceExpression
|
|
10
|
+
|
|
1
11
|
2025.08.05, v15.18.1
|
|
2
12
|
|
|
3
13
|
feature:
|
|
@@ -2,15 +2,36 @@
|
|
|
2
2
|
|
|
3
3
|
const {types} = require('@putout/babel');
|
|
4
4
|
const {hasLeadingComment} = require('#is');
|
|
5
|
-
const noop = () => {};
|
|
6
5
|
const {isReturnStatement} = types;
|
|
7
6
|
|
|
8
|
-
module.exports.printLeadingCommentLine =
|
|
7
|
+
module.exports.printLeadingCommentLine = (path, printer, semantics, {printComment, isLast}) => {
|
|
8
|
+
const {parentPath} = path;
|
|
9
|
+
const {print, maybe} = printer;
|
|
10
|
+
|
|
11
|
+
if (isReturnStatement(parentPath))
|
|
12
|
+
return;
|
|
13
|
+
|
|
14
|
+
maybe.print.breakline(!isLast);
|
|
15
|
+
printComment();
|
|
16
|
+
print.breakline();
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
module.exports.printLeadingCommentBlock = (path, printer, semantics, {printComment}) => {
|
|
20
|
+
const {parentPath} = path;
|
|
21
|
+
const {print} = printer;
|
|
22
|
+
|
|
23
|
+
if (isReturnStatement(parentPath))
|
|
24
|
+
return;
|
|
25
|
+
|
|
26
|
+
printComment();
|
|
27
|
+
print.indent();
|
|
28
|
+
};
|
|
9
29
|
|
|
10
30
|
module.exports.maybeInsideReturnWithCommentStart = (path, {print, indent}) => {
|
|
11
31
|
const {parentPath} = path;
|
|
32
|
+
const is = isReturnStatement(parentPath);
|
|
12
33
|
|
|
13
|
-
if (
|
|
34
|
+
if (is && hasLeadingComment(path)) {
|
|
14
35
|
indent.inc();
|
|
15
36
|
const {leadingComments} = path.node;
|
|
16
37
|
|
|
@@ -28,8 +49,9 @@ module.exports.maybeInsideReturnWithCommentStart = (path, {print, indent}) => {
|
|
|
28
49
|
|
|
29
50
|
module.exports.maybeInsideReturnWithCommentEnd = (path, {print, indent}) => {
|
|
30
51
|
const {parentPath} = path;
|
|
52
|
+
const is = isReturnStatement(parentPath);
|
|
31
53
|
|
|
32
|
-
if (!
|
|
54
|
+
if (!is || !hasLeadingComment(path))
|
|
33
55
|
return;
|
|
34
56
|
|
|
35
57
|
indent.dec();
|
|
@@ -6,6 +6,7 @@ const {
|
|
|
6
6
|
printLeadingCommentLine,
|
|
7
7
|
maybeInsideReturnWithCommentEnd,
|
|
8
8
|
maybeInsideReturnWithCommentStart,
|
|
9
|
+
printLeadingCommentBlock,
|
|
9
10
|
} = require('./assignment-expression-comments');
|
|
10
11
|
|
|
11
12
|
const {maybeParens} = require('../../maybe/maybe-parens');
|
|
@@ -38,3 +39,4 @@ module.exports.AssignmentExpression = maybeParens({
|
|
|
38
39
|
});
|
|
39
40
|
|
|
40
41
|
module.exports.AssignmentExpression.printLeadingCommentLine = printLeadingCommentLine;
|
|
42
|
+
module.exports.AssignmentExpression.printLeadingCommentBlock = printLeadingCommentBlock;
|
|
@@ -1,40 +1,18 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
module.exports.
|
|
4
|
-
maybeWriteBrace(path, printer, semantics, {
|
|
5
|
-
brace: '(',
|
|
6
|
-
});
|
|
7
|
-
};
|
|
8
|
-
|
|
9
|
-
module.exports.maybeWriteRightBrace = (path, printer, semantics) => {
|
|
10
|
-
maybeWriteBrace(path, printer, semantics, {
|
|
11
|
-
brace: ')',
|
|
12
|
-
});
|
|
13
|
-
};
|
|
14
|
-
|
|
15
|
-
function maybeWriteBrace(path, printer, semantics, {brace}) {
|
|
3
|
+
module.exports.condition = (path, printer, semantics) => {
|
|
16
4
|
const {parentPath} = path;
|
|
17
5
|
const {type} = parentPath;
|
|
18
6
|
const {roundBraces} = semantics;
|
|
19
|
-
const {write} = printer;
|
|
20
|
-
|
|
21
|
-
if (type === 'ArrowFunctionExpression') {
|
|
22
|
-
write(brace);
|
|
23
|
-
return;
|
|
24
|
-
}
|
|
25
7
|
|
|
26
|
-
if (type === '
|
|
27
|
-
|
|
28
|
-
return;
|
|
29
|
-
}
|
|
8
|
+
if (type === 'ArrowFunctionExpression')
|
|
9
|
+
return true;
|
|
30
10
|
|
|
31
|
-
if (type === '
|
|
32
|
-
|
|
33
|
-
return;
|
|
34
|
-
}
|
|
11
|
+
if (type === 'ConditionalExpression' && path !== parentPath.get('test'))
|
|
12
|
+
return true;
|
|
35
13
|
|
|
36
|
-
if (
|
|
37
|
-
return;
|
|
14
|
+
if (type === 'LogicalExpression')
|
|
15
|
+
return true;
|
|
38
16
|
|
|
39
|
-
|
|
40
|
-
}
|
|
17
|
+
return roundBraces.sequence;
|
|
18
|
+
};
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const {hasLeadingComment} = require('#is');
|
|
4
|
+
const noop = () => {};
|
|
5
|
+
|
|
6
|
+
module.exports.printLeadingCommentLine = noop;
|
|
7
|
+
module.exports.printLeadingCommentBlock = noop;
|
|
8
|
+
|
|
9
|
+
module.exports.maybePrintComments = (path, {print}) => {
|
|
10
|
+
if (hasLeadingComment(path)) {
|
|
11
|
+
const {leadingComments} = path.node;
|
|
12
|
+
|
|
13
|
+
for (const {type, value} of leadingComments) {
|
|
14
|
+
if (type === 'CommentLine')
|
|
15
|
+
print(`//${value}`);
|
|
16
|
+
else
|
|
17
|
+
print(`/*${value}*/`);
|
|
18
|
+
|
|
19
|
+
print.breakline();
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
};
|
|
@@ -1,23 +1,53 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
+
const {hasLeadingComment} = require('#is');
|
|
4
|
+
const {maybeParens} = require('../../maybe/maybe-parens');
|
|
5
|
+
const {condition} = require('./maybe-write-brace');
|
|
6
|
+
|
|
3
7
|
const {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
8
|
+
maybePrintComments,
|
|
9
|
+
printLeadingCommentLine,
|
|
10
|
+
printLeadingCommentBlock,
|
|
11
|
+
} = require('./sequence-expression-comments');
|
|
12
|
+
|
|
13
|
+
module.exports.SequenceExpression = maybeParens({
|
|
14
|
+
checkParens: false,
|
|
15
|
+
condition,
|
|
16
|
+
print(path, printer) {
|
|
17
|
+
const {
|
|
18
|
+
write,
|
|
19
|
+
traverse,
|
|
20
|
+
indent,
|
|
21
|
+
maybe,
|
|
22
|
+
} = printer;
|
|
23
|
+
|
|
24
|
+
const expressions = path.get('expressions');
|
|
25
|
+
const n = expressions.length - 1;
|
|
26
|
+
|
|
27
|
+
const withComment = hasLeadingComment(path);
|
|
28
|
+
|
|
29
|
+
if (withComment) {
|
|
30
|
+
indent.inc();
|
|
31
|
+
write.breakline();
|
|
32
|
+
maybePrintComments(path, printer);
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
for (const [index, expression] of expressions.entries()) {
|
|
36
|
+
traverse(expression);
|
|
37
|
+
|
|
38
|
+
if (index < n) {
|
|
39
|
+
write(',');
|
|
40
|
+
maybe.write.space(!withComment);
|
|
41
|
+
maybe.print.breakline(withComment);
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
if (withComment) {
|
|
46
|
+
indent.dec();
|
|
47
|
+
write.breakline();
|
|
48
|
+
}
|
|
49
|
+
},
|
|
50
|
+
});
|
|
7
51
|
|
|
8
|
-
module.exports.SequenceExpression =
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
const expressions = path.get('expressions');
|
|
12
|
-
const n = expressions.length - 1;
|
|
13
|
-
|
|
14
|
-
maybeWriteLeftBrace(path, printer, semantics);
|
|
15
|
-
|
|
16
|
-
for (const [index, expression] of expressions.entries()) {
|
|
17
|
-
traverse(expression);
|
|
18
|
-
maybe.write(index < n, ',');
|
|
19
|
-
maybe.write.space(index < n);
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
maybeWriteRightBrace(path, printer, semantics);
|
|
23
|
-
};
|
|
52
|
+
module.exports.SequenceExpression.printLeadingCommentLine = printLeadingCommentLine;
|
|
53
|
+
module.exports.SequenceExpression.printLeadingCommentBlock = printLeadingCommentBlock;
|
package/package.json
CHANGED