@putout/printer 18.21.1 → 18.23.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.26, v18.23.0
|
|
2
|
+
|
|
3
|
+
feature:
|
|
4
|
+
- 7533ce0b @putout/printer: ObjectExpression inside TSAsExpression: round braces
|
|
5
|
+
|
|
6
|
+
2026.06.23, v18.22.0
|
|
7
|
+
|
|
8
|
+
feature:
|
|
9
|
+
- 527905d1 @putout/printer: TSModuleDeclaration: after: newline
|
|
10
|
+
|
|
1
11
|
2026.06.22, v18.21.1
|
|
2
12
|
|
|
3
13
|
fix:
|
|
@@ -1,6 +1,7 @@
|
|
|
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,
|
|
@@ -73,68 +74,68 @@ const isIndentBeforeProperty = createTypeChecker([
|
|
|
73
74
|
['+: -> !', hasLeadingComment],
|
|
74
75
|
]);
|
|
75
76
|
|
|
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();
|
|
77
|
+
export const ObjectExpression = maybeParens({
|
|
78
|
+
condition: isParens,
|
|
79
|
+
print: (path, printer, semantics) => {
|
|
80
|
+
const {trailingComma} = semantics;
|
|
81
|
+
const {
|
|
82
|
+
print,
|
|
83
|
+
maybe,
|
|
84
|
+
indent,
|
|
85
|
+
} = printer;
|
|
104
86
|
|
|
105
|
-
|
|
87
|
+
const insideNestedArrayCall = isInsideNestedArrayCall(path);
|
|
106
88
|
|
|
107
|
-
|
|
108
|
-
continue;
|
|
89
|
+
maybe.indent.inc(!insideNestedArrayCall);
|
|
109
90
|
|
|
110
|
-
|
|
111
|
-
continue;
|
|
91
|
+
const properties = path.get('properties');
|
|
112
92
|
|
|
113
|
-
|
|
114
|
-
multiline,
|
|
115
|
-
trailingComma,
|
|
116
|
-
}), ',');
|
|
93
|
+
const multiline = isMultiline(path);
|
|
117
94
|
|
|
118
|
-
|
|
119
|
-
|
|
95
|
+
print('{');
|
|
96
|
+
parseComments(path, printer, semantics);
|
|
97
|
+
maybe.print.newline(multiline);
|
|
120
98
|
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
99
|
+
const memberCallee = isMemberExpressionCallee(path);
|
|
100
|
+
maybe.indent.inc(memberCallee);
|
|
101
|
+
|
|
102
|
+
for (const property of properties) {
|
|
103
|
+
if (isIndentBeforeProperty(property, {multiline}))
|
|
104
|
+
indent();
|
|
105
|
+
|
|
106
|
+
print(property);
|
|
107
|
+
|
|
108
|
+
if (property.isObjectMethod())
|
|
109
|
+
continue;
|
|
110
|
+
|
|
111
|
+
if (hasTrailingComment(property))
|
|
112
|
+
continue;
|
|
113
|
+
|
|
114
|
+
maybe.print(isCommaAfterSpread(property, {
|
|
115
|
+
multiline,
|
|
116
|
+
trailingComma,
|
|
117
|
+
}), ',');
|
|
118
|
+
|
|
119
|
+
if (isNewlineAfterProperty(property, {multiline}))
|
|
120
|
+
print.newline();
|
|
121
|
+
|
|
122
|
+
if (isLinebreakAfterProperty(property))
|
|
123
|
+
print.linebreak();
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
indent.dec();
|
|
127
|
+
|
|
128
|
+
if (isIndentBeforeClosingCurlyBrace(path, {multiline}))
|
|
129
|
+
indent();
|
|
130
|
+
|
|
131
|
+
if (insideNestedArrayCall)
|
|
132
|
+
indent.inc();
|
|
133
|
+
|
|
134
|
+
print('}');
|
|
135
|
+
|
|
136
|
+
maybe.indent.dec(memberCallee);
|
|
137
|
+
},
|
|
138
|
+
});
|
|
138
139
|
|
|
139
140
|
const isIndentBeforeClosingCurlyBrace = createTypeChecker([
|
|
140
141
|
['+', isInsideTupleLike],
|
|
@@ -1,6 +1,8 @@
|
|
|
1
|
-
import {isNext} from '#is';
|
|
1
|
+
import {isNext, callWithParent} from '#is';
|
|
2
2
|
import {maybeDeclare} from '#maybe-declare';
|
|
3
3
|
|
|
4
|
+
const isNextParent = callWithParent(isNext);
|
|
5
|
+
|
|
4
6
|
export const TSModuleDeclaration = {
|
|
5
7
|
print: maybeDeclare((path, {print}) => {
|
|
6
8
|
const {kind} = path.node;
|
|
@@ -14,6 +16,9 @@ export const TSModuleDeclaration = {
|
|
|
14
16
|
print('__id');
|
|
15
17
|
print.space();
|
|
16
18
|
print('__body');
|
|
19
|
+
|
|
20
|
+
if (isNextParent(path))
|
|
21
|
+
print.newline();
|
|
17
22
|
}),
|
|
18
23
|
afterSatisfy: () => [
|
|
19
24
|
isNext,
|
|
@@ -1,27 +1,7 @@
|
|
|
1
|
-
import {types} from '@putout/babel';
|
|
2
1
|
import {maybeParens} from '#maybe-parens';
|
|
3
2
|
|
|
4
|
-
const {
|
|
5
|
-
isVariableDeclarator,
|
|
6
|
-
isObjectExpression,
|
|
7
|
-
} = types;
|
|
8
|
-
|
|
9
|
-
export const TSAsExpression = maybeParens((path, {print, maybe}) => {
|
|
10
|
-
const is = isParens(path);
|
|
11
|
-
|
|
12
|
-
maybe.print(is, '(');
|
|
3
|
+
export const TSAsExpression = maybeParens((path, {print}) => {
|
|
13
4
|
print('__expression');
|
|
14
|
-
maybe.print(is, ')');
|
|
15
|
-
|
|
16
5
|
print(' as ');
|
|
17
6
|
print('__typeAnnotation');
|
|
18
7
|
});
|
|
19
|
-
|
|
20
|
-
function isParens(path) {
|
|
21
|
-
const {expression} = path.node;
|
|
22
|
-
|
|
23
|
-
if (isVariableDeclarator(path.parentPath))
|
|
24
|
-
return false;
|
|
25
|
-
|
|
26
|
-
return isObjectExpression(expression);
|
|
27
|
-
}
|
package/package.json
CHANGED