@putout/printer 18.22.0 → 18.24.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
|
+
2026.06.27, v18.24.0
|
|
2
|
+
|
|
3
|
+
feature:
|
|
4
|
+
- 524967f6 @putout/printer: ObjectExpression inside TSAsExpression
|
|
5
|
+
|
|
6
|
+
2026.06.26, v18.23.0
|
|
7
|
+
|
|
8
|
+
feature:
|
|
9
|
+
- 7533ce0b @putout/printer: ObjectExpression inside TSAsExpression: round braces
|
|
10
|
+
|
|
1
11
|
2026.06.23, v18.22.0
|
|
2
12
|
|
|
3
13
|
feature:
|
|
@@ -1,15 +1,16 @@
|
|
|
1
1
|
import {types} from '@putout/babel';
|
|
2
2
|
import {createTypeChecker} from '#type-checker';
|
|
3
3
|
import {parseComments} from '#comments';
|
|
4
|
+
import {maybeParens} from '#maybe-parens';
|
|
4
5
|
import {
|
|
5
6
|
isCoupleLines,
|
|
6
7
|
isForOf,
|
|
7
8
|
isIf,
|
|
8
9
|
hasLeadingComment,
|
|
9
10
|
isInsideCall,
|
|
10
|
-
isInsideBody,
|
|
11
11
|
isInsideExpression,
|
|
12
12
|
hasTrailingComment,
|
|
13
|
+
callWithParent,
|
|
13
14
|
} from '#is';
|
|
14
15
|
import {isInsideTuple} from './is-inside-tuple.js';
|
|
15
16
|
import {isLooksLikeChain} from '../member-expression/is-looks-like-chain/index.js';
|
|
@@ -33,9 +34,17 @@ const notLastArgInsideCall = (path) => {
|
|
|
33
34
|
const hasNoProperties = (path) => !path.node.properties.length;
|
|
34
35
|
const hasValue = (path) => path.node.properties[0].value;
|
|
35
36
|
|
|
36
|
-
const {
|
|
37
|
+
const {
|
|
38
|
+
isMemberExpression,
|
|
39
|
+
isAssignmentExpression,
|
|
40
|
+
isArrowFunctionExpression,
|
|
41
|
+
} = types;
|
|
37
42
|
|
|
38
|
-
const isParens = createTypeChecker([
|
|
43
|
+
const isParens = createTypeChecker([
|
|
44
|
+
['-', callWithParent(isAssignmentExpression)],
|
|
45
|
+
['+', callWithParent(isArrowFunctionExpression)],
|
|
46
|
+
['+', isInsideExpression],
|
|
47
|
+
]);
|
|
39
48
|
|
|
40
49
|
const callWithCallee = (fn) => (a) => fn(a.get('callee'));
|
|
41
50
|
|
|
@@ -73,68 +82,69 @@ const isIndentBeforeProperty = createTypeChecker([
|
|
|
73
82
|
['+: -> !', hasLeadingComment],
|
|
74
83
|
]);
|
|
75
84
|
|
|
76
|
-
export const ObjectExpression = (
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
maybe.indent.inc(!insideNestedArrayCall);
|
|
87
|
-
|
|
88
|
-
const properties = path.get('properties');
|
|
89
|
-
|
|
90
|
-
const parens = isParens(path);
|
|
91
|
-
const multiline = isMultiline(path);
|
|
92
|
-
|
|
93
|
-
maybe.print(parens, '(');
|
|
94
|
-
print('{');
|
|
95
|
-
parseComments(path, printer, semantics);
|
|
96
|
-
maybe.print.newline(multiline);
|
|
97
|
-
|
|
98
|
-
const memberCallee = isMemberExpressionCallee(path);
|
|
99
|
-
maybe.indent.inc(memberCallee);
|
|
100
|
-
|
|
101
|
-
for (const property of properties) {
|
|
102
|
-
if (isIndentBeforeProperty(property, {multiline}))
|
|
103
|
-
indent();
|
|
85
|
+
export const ObjectExpression = maybeParens({
|
|
86
|
+
checkParens: false,
|
|
87
|
+
condition: isParens,
|
|
88
|
+
print: (path, printer, semantics) => {
|
|
89
|
+
const {trailingComma} = semantics;
|
|
90
|
+
const {
|
|
91
|
+
print,
|
|
92
|
+
maybe,
|
|
93
|
+
indent,
|
|
94
|
+
} = printer;
|
|
104
95
|
|
|
105
|
-
|
|
96
|
+
const insideNestedArrayCall = isInsideNestedArrayCall(path);
|
|
106
97
|
|
|
107
|
-
|
|
108
|
-
continue;
|
|
98
|
+
maybe.indent.inc(!insideNestedArrayCall);
|
|
109
99
|
|
|
110
|
-
|
|
111
|
-
continue;
|
|
100
|
+
const properties = path.get('properties');
|
|
112
101
|
|
|
113
|
-
|
|
114
|
-
multiline,
|
|
115
|
-
trailingComma,
|
|
116
|
-
}), ',');
|
|
102
|
+
const multiline = isMultiline(path);
|
|
117
103
|
|
|
118
|
-
|
|
119
|
-
|
|
104
|
+
print('{');
|
|
105
|
+
parseComments(path, printer, semantics);
|
|
106
|
+
maybe.print.newline(multiline);
|
|
120
107
|
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
108
|
+
const memberCallee = isMemberExpressionCallee(path);
|
|
109
|
+
maybe.indent.inc(memberCallee);
|
|
110
|
+
|
|
111
|
+
for (const property of properties) {
|
|
112
|
+
if (isIndentBeforeProperty(property, {multiline}))
|
|
113
|
+
indent();
|
|
114
|
+
|
|
115
|
+
print(property);
|
|
116
|
+
|
|
117
|
+
if (property.isObjectMethod())
|
|
118
|
+
continue;
|
|
119
|
+
|
|
120
|
+
if (hasTrailingComment(property))
|
|
121
|
+
continue;
|
|
122
|
+
|
|
123
|
+
maybe.print(isCommaAfterSpread(property, {
|
|
124
|
+
multiline,
|
|
125
|
+
trailingComma,
|
|
126
|
+
}), ',');
|
|
127
|
+
|
|
128
|
+
if (isNewlineAfterProperty(property, {multiline}))
|
|
129
|
+
print.newline();
|
|
130
|
+
|
|
131
|
+
if (isLinebreakAfterProperty(property))
|
|
132
|
+
print.linebreak();
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
indent.dec();
|
|
136
|
+
|
|
137
|
+
if (isIndentBeforeClosingCurlyBrace(path, {multiline}))
|
|
138
|
+
indent();
|
|
139
|
+
|
|
140
|
+
if (insideNestedArrayCall)
|
|
141
|
+
indent.inc();
|
|
142
|
+
|
|
143
|
+
print('}');
|
|
144
|
+
|
|
145
|
+
maybe.indent.dec(memberCallee);
|
|
146
|
+
},
|
|
147
|
+
});
|
|
138
148
|
|
|
139
149
|
const isIndentBeforeClosingCurlyBrace = createTypeChecker([
|
|
140
150
|
['+', isInsideTupleLike],
|
|
@@ -1,27 +1,24 @@
|
|
|
1
1
|
import {types} from '@putout/babel';
|
|
2
2
|
import {maybeParens} from '#maybe-parens';
|
|
3
|
+
import {createTypeChecker} from '#type-checker';
|
|
4
|
+
import {callWithParent} from '#is';
|
|
3
5
|
|
|
4
6
|
const {
|
|
7
|
+
isCallExpression,
|
|
5
8
|
isVariableDeclarator,
|
|
6
|
-
isObjectExpression,
|
|
7
9
|
} = types;
|
|
8
10
|
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
maybe.print(is, ')');
|
|
15
|
-
|
|
16
|
-
print(' as ');
|
|
17
|
-
print('__typeAnnotation');
|
|
18
|
-
});
|
|
11
|
+
const condition = createTypeChecker([
|
|
12
|
+
['-', callWithParent(isCallExpression)],
|
|
13
|
+
['-', callWithParent(isVariableDeclarator)],
|
|
14
|
+
['+: node.expression -> ObjectExpression'],
|
|
15
|
+
]);
|
|
19
16
|
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
}
|
|
17
|
+
export const TSAsExpression = maybeParens({
|
|
18
|
+
condition,
|
|
19
|
+
print: (path, {print}) => {
|
|
20
|
+
print('__expression');
|
|
21
|
+
print(' as ');
|
|
22
|
+
print('__typeAnnotation');
|
|
23
|
+
},
|
|
24
|
+
});
|
package/package.json
CHANGED