@putout/printer 15.18.2 → 15.20.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 +14 -2
- package/lib/tokenize/expressions/assignment-expression/assignment-expression.js +2 -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/lib/tokenize/jsx/index.js +1 -1
- package/lib/tokenize/jsx/{jsx-text.js → jsx-text/jsx-text.js} +2 -2
- package/package.json +1 -1
package/ChangeLog
CHANGED
|
@@ -1,3 +1,13 @@
|
|
|
1
|
+
2025.08.12, v15.20.0
|
|
2
|
+
|
|
3
|
+
feature:
|
|
4
|
+
- 0eb1ddd @putout/printer: JSXText: no extra
|
|
5
|
+
|
|
6
|
+
2025.08.05, v15.19.0
|
|
7
|
+
|
|
8
|
+
feature:
|
|
9
|
+
- f518cd6 @putout/printer: SequenceExpression: leadingComments inside AssignmentExpressions: improve
|
|
10
|
+
|
|
1
11
|
2025.08.05, v15.18.2
|
|
2
12
|
|
|
3
13
|
feature:
|
|
@@ -4,7 +4,19 @@ const {types} = require('@putout/babel');
|
|
|
4
4
|
const {hasLeadingComment} = require('#is');
|
|
5
5
|
const {isReturnStatement} = types;
|
|
6
6
|
|
|
7
|
-
module.exports.printLeadingCommentLine = (path, printer, semantics, {printComment}) => {
|
|
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}) => {
|
|
8
20
|
const {parentPath} = path;
|
|
9
21
|
const {print} = printer;
|
|
10
22
|
|
|
@@ -12,7 +24,7 @@ module.exports.printLeadingCommentLine = (path, printer, semantics, {printCommen
|
|
|
12
24
|
return;
|
|
13
25
|
|
|
14
26
|
printComment();
|
|
15
|
-
print.
|
|
27
|
+
print.indent();
|
|
16
28
|
};
|
|
17
29
|
|
|
18
30
|
module.exports.maybeInsideReturnWithCommentStart = (path, {print, indent}) => {
|
|
@@ -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;
|
|
@@ -5,7 +5,7 @@ const {JSXAttribute} = require('./jsx-attribute');
|
|
|
5
5
|
const {isCoupleLines} = require('../is');
|
|
6
6
|
const {JSXOpeningElement} = require('./jsx-opening-element');
|
|
7
7
|
const fragments = require('./jsx-fragment');
|
|
8
|
-
const {JSXText} = require('./jsx-text');
|
|
8
|
+
const {JSXText} = require('./jsx-text/jsx-text');
|
|
9
9
|
const {parseComments} = require('../comment/comment');
|
|
10
10
|
|
|
11
11
|
module.exports = {
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
const {isNext} = require('
|
|
3
|
+
const {isNext} = require('#is');
|
|
4
4
|
|
|
5
5
|
module.exports.JSXText = (path, {write, indent}) => {
|
|
6
6
|
const {node} = path;
|
|
@@ -8,7 +8,7 @@ module.exports.JSXText = (path, {write, indent}) => {
|
|
|
8
8
|
const isSpacesOnly = /^\s+$/.test(value);
|
|
9
9
|
const hasNext = isNext(path);
|
|
10
10
|
|
|
11
|
-
if (extra
|
|
11
|
+
if (extra?.raw.includes('&'))
|
|
12
12
|
return write(extra.raw);
|
|
13
13
|
|
|
14
14
|
if (isSpacesOnly && hasNext) {
|
package/package.json
CHANGED