@putout/printer 15.18.0 → 15.18.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/expressions/assignment-expression/assignment-expression-comments.js +14 -4
- package/lib/tokenize/expressions/assignment-expression/assignment-expression.js +25 -45
- package/lib/tokenize/expressions/assignment-expression/maybe-parens-condition.js +28 -0
- package/lib/tokenize/expressions/assignment-expression/print-separator.js +23 -0
- package/lib/tokenize/maybe/maybe-parens.js +9 -2
- package/package.json +1 -1
- package/lib/tokenize/expressions/assignment-expression/maybe-write-brace.js +0 -51
package/ChangeLog
CHANGED
|
@@ -1,3 +1,13 @@
|
|
|
1
|
+
2025.08.05, v15.18.2
|
|
2
|
+
|
|
3
|
+
feature:
|
|
4
|
+
- a7fd7cc @putout/printer: AssignmentExpression: comments: inside SequenceExpression
|
|
5
|
+
|
|
6
|
+
2025.08.05, v15.18.1
|
|
7
|
+
|
|
8
|
+
feature:
|
|
9
|
+
- 59d5952 @putout/printer: AssignmentExpression: maybeParens
|
|
10
|
+
|
|
1
11
|
2025.08.04, v15.18.0
|
|
2
12
|
|
|
3
13
|
feature:
|
|
@@ -4,12 +4,22 @@ const {types} = require('@putout/babel');
|
|
|
4
4
|
const {hasLeadingComment} = require('#is');
|
|
5
5
|
const {isReturnStatement} = types;
|
|
6
6
|
|
|
7
|
-
module.exports.printLeadingCommentLine = ({
|
|
7
|
+
module.exports.printLeadingCommentLine = (path, printer, semantics, {printComment}) => {
|
|
8
|
+
const {parentPath} = path;
|
|
9
|
+
const {print} = printer;
|
|
10
|
+
|
|
11
|
+
if (isReturnStatement(parentPath))
|
|
12
|
+
return;
|
|
13
|
+
|
|
14
|
+
printComment();
|
|
15
|
+
print.newline();
|
|
16
|
+
};
|
|
8
17
|
|
|
9
18
|
module.exports.maybeInsideReturnWithCommentStart = (path, {print, indent}) => {
|
|
10
19
|
const {parentPath} = path;
|
|
20
|
+
const is = isReturnStatement(parentPath);
|
|
11
21
|
|
|
12
|
-
if (
|
|
22
|
+
if (is && hasLeadingComment(path)) {
|
|
13
23
|
indent.inc();
|
|
14
24
|
const {leadingComments} = path.node;
|
|
15
25
|
|
|
@@ -27,11 +37,11 @@ module.exports.maybeInsideReturnWithCommentStart = (path, {print, indent}) => {
|
|
|
27
37
|
|
|
28
38
|
module.exports.maybeInsideReturnWithCommentEnd = (path, {print, indent}) => {
|
|
29
39
|
const {parentPath} = path;
|
|
40
|
+
const is = isReturnStatement(parentPath);
|
|
30
41
|
|
|
31
|
-
if (!
|
|
42
|
+
if (!is || !hasLeadingComment(path))
|
|
32
43
|
return;
|
|
33
44
|
|
|
34
45
|
indent.dec();
|
|
35
46
|
print.breakline();
|
|
36
47
|
};
|
|
37
|
-
|
|
@@ -1,11 +1,6 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
const {
|
|
4
|
-
|
|
5
|
-
const {
|
|
6
|
-
maybePrintLeftBrace,
|
|
7
|
-
maybePrintRightBrace,
|
|
8
|
-
} = require('./maybe-write-brace');
|
|
3
|
+
const {condition} = require('./maybe-parens-condition');
|
|
9
4
|
|
|
10
5
|
const {
|
|
11
6
|
printLeadingCommentLine,
|
|
@@ -13,48 +8,33 @@ const {
|
|
|
13
8
|
maybeInsideReturnWithCommentStart,
|
|
14
9
|
} = require('./assignment-expression-comments');
|
|
15
10
|
|
|
16
|
-
const {
|
|
17
|
-
|
|
18
|
-
isAssignmentExpression,
|
|
19
|
-
} = types;
|
|
11
|
+
const {maybeParens} = require('../../maybe/maybe-parens');
|
|
12
|
+
const {printSeparator} = require('./print-separator');
|
|
20
13
|
|
|
21
14
|
const isInsideBlock = ({parentPath}) => /BlockStatement|Program/.test(parentPath.type);
|
|
22
15
|
|
|
23
|
-
module.exports.AssignmentExpression = (
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
if (isMultiline(path))
|
|
35
|
-
print.breakline();
|
|
36
|
-
else
|
|
16
|
+
module.exports.AssignmentExpression = maybeParens({
|
|
17
|
+
checkParens: false,
|
|
18
|
+
condition,
|
|
19
|
+
print(path, printer) {
|
|
20
|
+
const {print} = printer;
|
|
21
|
+
const {operator} = path.node;
|
|
22
|
+
|
|
23
|
+
maybeInsideReturnWithCommentStart(path, printer);
|
|
24
|
+
|
|
25
|
+
print('__left');
|
|
37
26
|
print.space();
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
};
|
|
27
|
+
print(operator);
|
|
28
|
+
printSeparator(path, printer);
|
|
29
|
+
print('__right');
|
|
30
|
+
|
|
31
|
+
if (isInsideBlock(path)) {
|
|
32
|
+
print(';');
|
|
33
|
+
print.breakline();
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
maybeInsideReturnWithCommentEnd(path, printer);
|
|
37
|
+
},
|
|
38
|
+
});
|
|
50
39
|
|
|
51
40
|
module.exports.AssignmentExpression.printLeadingCommentLine = printLeadingCommentLine;
|
|
52
|
-
|
|
53
|
-
function isMultiline(path) {
|
|
54
|
-
const {right} = path.node;
|
|
55
|
-
|
|
56
|
-
if (!path.parentPath.find(isExpressionStatement))
|
|
57
|
-
return false;
|
|
58
|
-
|
|
59
|
-
return isAssignmentExpression(right);
|
|
60
|
-
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const {hasLeadingComment} = require('#is');
|
|
4
|
+
|
|
5
|
+
const {isParens} = require('../../maybe/maybe-parens');
|
|
6
|
+
|
|
7
|
+
module.exports.condition = (path, printer, semantics) => {
|
|
8
|
+
const {parentPath} = path;
|
|
9
|
+
const {type} = parentPath;
|
|
10
|
+
const {roundBraces} = semantics;
|
|
11
|
+
|
|
12
|
+
if (path.node.left.type === 'ObjectPattern')
|
|
13
|
+
return true;
|
|
14
|
+
|
|
15
|
+
if (type === 'LogicalExpression')
|
|
16
|
+
return true;
|
|
17
|
+
|
|
18
|
+
if (type === 'BinaryExpression')
|
|
19
|
+
return true;
|
|
20
|
+
|
|
21
|
+
if (type === 'UnaryExpression')
|
|
22
|
+
return true;
|
|
23
|
+
|
|
24
|
+
if (!roundBraces.assign && !hasLeadingComment(path))
|
|
25
|
+
return false;
|
|
26
|
+
|
|
27
|
+
return isParens(path);
|
|
28
|
+
};
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const {types} = require('@putout/babel');
|
|
4
|
+
const {
|
|
5
|
+
isAssignmentExpression,
|
|
6
|
+
isExpressionStatement,
|
|
7
|
+
} = types;
|
|
8
|
+
|
|
9
|
+
module.exports.printSeparator = (path, {print}) => {
|
|
10
|
+
if (isMultiline(path))
|
|
11
|
+
print.breakline();
|
|
12
|
+
else
|
|
13
|
+
print.space();
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
function isMultiline(path) {
|
|
17
|
+
const {right} = path.node;
|
|
18
|
+
|
|
19
|
+
if (!path.parentPath.find(isExpressionStatement))
|
|
20
|
+
return false;
|
|
21
|
+
|
|
22
|
+
return isAssignmentExpression(right);
|
|
23
|
+
}
|
|
@@ -22,7 +22,14 @@ const maybeParensPrint = (print) => ({
|
|
|
22
22
|
},
|
|
23
23
|
});
|
|
24
24
|
|
|
25
|
-
const maybeParensCondition = ({print, condition}) => ({
|
|
25
|
+
const maybeParensCondition = ({print, condition, checkParens = true}) => ({
|
|
26
26
|
...maybeParensPrint(print),
|
|
27
|
-
condition: (path
|
|
27
|
+
condition: (path, print, semantics) => {
|
|
28
|
+
const is = condition?.(path, print, semantics);
|
|
29
|
+
|
|
30
|
+
if (!checkParens)
|
|
31
|
+
return is;
|
|
32
|
+
|
|
33
|
+
return is || isParens(path);
|
|
34
|
+
},
|
|
28
35
|
});
|
package/package.json
CHANGED
|
@@ -1,51 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
const {hasLeadingComment} = require('#is');
|
|
4
|
-
const {isParens} = require('../../maybe/maybe-parens');
|
|
5
|
-
|
|
6
|
-
module.exports.maybePrintLeftBrace = (path, printer, semantics) => {
|
|
7
|
-
maybeWriteBrace(path, printer, semantics, {
|
|
8
|
-
brace: '(',
|
|
9
|
-
});
|
|
10
|
-
};
|
|
11
|
-
|
|
12
|
-
module.exports.maybePrintRightBrace = (path, printer, semantics) => {
|
|
13
|
-
maybeWriteBrace(path, printer, semantics, {
|
|
14
|
-
brace: ')',
|
|
15
|
-
});
|
|
16
|
-
};
|
|
17
|
-
|
|
18
|
-
function maybeWriteBrace(path, printer, semantics, {brace}) {
|
|
19
|
-
const {parentPath} = path;
|
|
20
|
-
const {type} = parentPath;
|
|
21
|
-
const {roundBraces} = semantics;
|
|
22
|
-
const {write} = printer;
|
|
23
|
-
|
|
24
|
-
if (path.node.left.type === 'ObjectPattern') {
|
|
25
|
-
write(brace);
|
|
26
|
-
return;
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
if (type === 'LogicalExpression') {
|
|
30
|
-
write(brace);
|
|
31
|
-
return;
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
if (type === 'BinaryExpression') {
|
|
35
|
-
write(brace);
|
|
36
|
-
return;
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
if (type === 'UnaryExpression') {
|
|
40
|
-
write(brace);
|
|
41
|
-
return;
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
if (!roundBraces.assign && !hasLeadingComment(path))
|
|
45
|
-
return;
|
|
46
|
-
|
|
47
|
-
if (!isParens(path))
|
|
48
|
-
return;
|
|
49
|
-
|
|
50
|
-
write(brace);
|
|
51
|
-
}
|