@putout/printer 15.26.1 → 15.27.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
CHANGED
|
@@ -1,3 +1,13 @@
|
|
|
1
|
+
2025.11.12, v15.27.0
|
|
2
|
+
|
|
3
|
+
feature:
|
|
4
|
+
- cd2a315 @putout/printer: MemberExpression: object is ObjectExpression: inside ArrowFunctionExpression
|
|
5
|
+
|
|
6
|
+
2025.11.07, v15.26.2
|
|
7
|
+
|
|
8
|
+
feature:
|
|
9
|
+
- c388dfa @putout/printer: IfStatement: consiquent is TryCatchStatement: add newline before else
|
|
10
|
+
|
|
1
11
|
2025.10.31, v15.26.1
|
|
2
12
|
|
|
3
13
|
feature:
|
|
@@ -1,37 +1,45 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
+
const {types} = require('@putout/babel');
|
|
3
4
|
const {maybePrintComputed} = require('../object-expression/maybe-print-computed');
|
|
4
5
|
const {maybeParens} = require('../../maybe/maybe-parens');
|
|
5
6
|
const {isLooksLikeChain} = require('./is-looks-like-chain');
|
|
6
7
|
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
8
|
+
const {
|
|
9
|
+
isObjectExpression,
|
|
10
|
+
isArrowFunctionExpression,
|
|
11
|
+
} = types;
|
|
12
|
+
|
|
13
|
+
module.exports.MemberExpression = maybeParens({
|
|
14
|
+
checkParens: false,
|
|
15
|
+
condition: (path) => isObjectInsideArrow(path),
|
|
16
|
+
print: (path, printer) => {
|
|
17
|
+
const {
|
|
18
|
+
print,
|
|
19
|
+
maybe,
|
|
20
|
+
traverse,
|
|
21
|
+
} = printer;
|
|
22
|
+
|
|
23
|
+
const object = path.get('object');
|
|
24
|
+
const property = path.get('property');
|
|
25
|
+
|
|
26
|
+
const {computed} = path.node;
|
|
27
|
+
|
|
28
|
+
const isChain = isLooksLikeChain(path);
|
|
29
|
+
|
|
30
|
+
traverse(object);
|
|
31
|
+
|
|
32
|
+
if (computed)
|
|
33
|
+
return maybePrintComputed(path, property, printer);
|
|
34
|
+
|
|
35
|
+
maybe.indent.inc(isChain);
|
|
36
|
+
maybe.print.breakline(isChain);
|
|
37
|
+
|
|
38
|
+
print('.');
|
|
39
|
+
print('__property');
|
|
40
|
+
maybe.indent.dec(isChain);
|
|
41
|
+
},
|
|
42
|
+
});
|
|
35
43
|
|
|
36
44
|
module.exports.OptionalMemberExpression = maybeParens((path, {print, maybe}) => {
|
|
37
45
|
const {computed, optional} = path.node;
|
|
@@ -51,3 +59,10 @@ module.exports.OptionalMemberExpression = maybeParens((path, {print, maybe}) =>
|
|
|
51
59
|
|
|
52
60
|
print('__property');
|
|
53
61
|
});
|
|
62
|
+
|
|
63
|
+
const isObjectInsideArrow = ({node, parentPath}) => {
|
|
64
|
+
if (!isObjectExpression(node.object))
|
|
65
|
+
return false;
|
|
66
|
+
|
|
67
|
+
return isArrowFunctionExpression(parentPath);
|
|
68
|
+
};
|
|
@@ -13,8 +13,24 @@ const {
|
|
|
13
13
|
isBlockStatement,
|
|
14
14
|
isFunctionDeclaration,
|
|
15
15
|
isStatement,
|
|
16
|
+
isExpressionStatement,
|
|
17
|
+
isReturnStatement,
|
|
18
|
+
isContinueStatement,
|
|
16
19
|
} = types;
|
|
17
20
|
|
|
21
|
+
const isStatementNotExpression = (path) => {
|
|
22
|
+
if (isBlockStatement(path))
|
|
23
|
+
return false;
|
|
24
|
+
|
|
25
|
+
if (isReturnStatement(path))
|
|
26
|
+
return false;
|
|
27
|
+
|
|
28
|
+
if (isContinueStatement(path))
|
|
29
|
+
return false;
|
|
30
|
+
|
|
31
|
+
return !isExpressionStatement(path);
|
|
32
|
+
};
|
|
33
|
+
|
|
18
34
|
const isTopLevel = ({parentPath}) => parentPath.parentPath.isProgram();
|
|
19
35
|
const isEmptyConsequent = (path) => path.get('consequent').isEmptyStatement();
|
|
20
36
|
|
|
@@ -83,15 +99,17 @@ module.exports.IfStatement = {
|
|
|
83
99
|
write.space();
|
|
84
100
|
traverse(alternate);
|
|
85
101
|
} else if (alternate.isIfStatement()) {
|
|
86
|
-
if (alternate.get('consequent').isBlockStatement())
|
|
102
|
+
if (alternate.get('consequent').isBlockStatement()) {
|
|
87
103
|
write.space();
|
|
88
|
-
else
|
|
104
|
+
} else {
|
|
105
|
+
maybe.write.newline(isStatementNotExpression(consequent));
|
|
89
106
|
indent();
|
|
107
|
+
}
|
|
90
108
|
|
|
91
109
|
write('else ');
|
|
92
110
|
traverse(alternate);
|
|
93
111
|
} else if (exists(alternate)) {
|
|
94
|
-
maybe.write.newline(isVar);
|
|
112
|
+
maybe.write.newline(isVar || isStatementNotExpression(consequent));
|
|
95
113
|
maybe.indent(!isConsequentBlock);
|
|
96
114
|
maybe.write.space(isConsequentBlock);
|
|
97
115
|
write('else');
|
package/package.json
CHANGED