@putout/printer 18.2.0 → 18.2.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 +11 -0
- package/lib/tokenize/expressions/array-expression/array-expression.js +19 -17
- package/lib/tokenize/expressions/array-expression/newline.js +5 -6
- package/lib/tokenize/is.js +1 -0
- package/lib/tokenize/statements/expression-statement/expression-statement.js +1 -1
- package/lib/tokenize/type-checker/instrument.js +0 -1
- package/lib/tokenize/type-checker/type-checker.js +1 -0
- package/package.json +1 -1
package/ChangeLog
CHANGED
|
@@ -1,3 +1,14 @@
|
|
|
1
|
+
2026.03.07, v18.2.2
|
|
2
|
+
|
|
3
|
+
feature:
|
|
4
|
+
- 7633d10 @putout/printer: ArrayExpression: isSimpleAfterObject
|
|
5
|
+
- c57048d @putout/printer: ArrayExpression: isCurrentNewLine: simplify
|
|
6
|
+
|
|
7
|
+
2026.03.07, v18.2.1
|
|
8
|
+
|
|
9
|
+
fix:
|
|
10
|
+
- b4e4b01 @putout/printer: ExpressionStatement
|
|
11
|
+
|
|
1
12
|
2026.03.07, v18.2.0
|
|
2
13
|
|
|
3
14
|
feature:
|
|
@@ -9,6 +9,7 @@ import {
|
|
|
9
9
|
isNextObject,
|
|
10
10
|
callWithNext,
|
|
11
11
|
isInsideArray,
|
|
12
|
+
callWithPrev,
|
|
12
13
|
} from '#is';
|
|
13
14
|
import {
|
|
14
15
|
isIncreaseIndent,
|
|
@@ -96,17 +97,18 @@ export const ArrayExpression = {
|
|
|
96
97
|
|
|
97
98
|
maybe.indent.inc(indented && shouldIncreaseIndent);
|
|
98
99
|
|
|
99
|
-
const
|
|
100
|
+
const needsNewline = isMultiLine(path, {
|
|
100
101
|
maxElementsInOneLine,
|
|
101
102
|
maxElementLengthInOneLine,
|
|
102
103
|
});
|
|
103
104
|
|
|
104
105
|
const n = elements.length - 1;
|
|
105
106
|
|
|
106
|
-
|
|
107
|
+
if (needsNewline)
|
|
108
|
+
print.newline();
|
|
107
109
|
|
|
108
110
|
for (const [index, element] of elements.entries()) {
|
|
109
|
-
const is =
|
|
111
|
+
const is = needsNewline && isCurrentNewLine(element);
|
|
110
112
|
|
|
111
113
|
if (isSimpleAfterObject(element))
|
|
112
114
|
print.newline();
|
|
@@ -139,10 +141,10 @@ export const ArrayExpression = {
|
|
|
139
141
|
const isHideIdent = !isAroundStrings(path) || parentCountTwo;
|
|
140
142
|
|
|
141
143
|
maybe.indent.dec(isHideIdent);
|
|
142
|
-
maybe.indent(elements.length &&
|
|
144
|
+
maybe.indent(elements.length && needsNewline);
|
|
143
145
|
maybe.indent.inc(isHideIdent);
|
|
144
146
|
} else if (!isArrayInsideArray(path) && !isObjectExpression(elements.at(-1))) {
|
|
145
|
-
maybe.indent(elements.length &&
|
|
147
|
+
maybe.indent(elements.length && needsNewline);
|
|
146
148
|
}
|
|
147
149
|
|
|
148
150
|
if (isSimpleAndNotEmptyObject(path) && !isSpreadElement(elements.at(-1)) && !isCallExpression(elements.at(-1))) {
|
|
@@ -173,15 +175,15 @@ export const ArrayExpression = {
|
|
|
173
175
|
},
|
|
174
176
|
};
|
|
175
177
|
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
178
|
+
const isSimple = createTypeChecker([
|
|
179
|
+
'-: -> SpreadElement',
|
|
180
|
+
'-: -> Identifier',
|
|
181
|
+
'+: -> !CallExpression',
|
|
182
|
+
]);
|
|
183
|
+
|
|
184
|
+
const isSimpleAfterObject = createTypeChecker([
|
|
185
|
+
['-', isSimple],
|
|
186
|
+
['-', callWithNext(isObjectExpression)],
|
|
187
|
+
['+', callWithPrev(isObjectExpression)],
|
|
188
|
+
]);
|
|
189
|
+
|
|
@@ -338,9 +338,8 @@ const isStringAndObject = (elements) => {
|
|
|
338
338
|
return isStringLiteral(first) && isObjectExpression(last);
|
|
339
339
|
};
|
|
340
340
|
|
|
341
|
-
export const isCurrentNewLine = (
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
};
|
|
341
|
+
export const isCurrentNewLine = createTypeChecker([
|
|
342
|
+
'+: -> SpreadElement',
|
|
343
|
+
'+: -> !ObjectExpression',
|
|
344
|
+
]);
|
|
345
|
+
|
package/lib/tokenize/is.js
CHANGED
|
@@ -31,6 +31,7 @@ export const isInsideTSModuleBlock = ({parentPath}) => isTSModuleBlock(parentPat
|
|
|
31
31
|
export const isInsideCall = ({parentPath}) => parentPath.isCallExpression();
|
|
32
32
|
export const isInsideReturn = ({parentPath}) => parentPath.isReturnStatement();
|
|
33
33
|
export const callWithNext = (fn) => (path) => fn(path.getNextSibling());
|
|
34
|
+
export const callWithPrev = (fn) => (path) => fn(path.getPrevSibling());
|
|
34
35
|
export const callWithParent = (fn) => (path) => fn(path.parentPath);
|
|
35
36
|
|
|
36
37
|
export const isNext = (path) => {
|
|
@@ -39,7 +39,7 @@ const isBreaklineAfter = createTypeChecker([
|
|
|
39
39
|
const isNextStatementWithBlockComment = createTypeChecker([
|
|
40
40
|
'-: node.expression -> !CallExpression',
|
|
41
41
|
'-: node.expression.arguments.0 -> !CallExpression',
|
|
42
|
-
'+: node.trailingComments.0 ->
|
|
42
|
+
'+: node.trailingComments.0 -> CommentBlock',
|
|
43
43
|
]);
|
|
44
44
|
|
|
45
45
|
const isBreakline = createTypeChecker([
|
|
@@ -12,6 +12,7 @@ export const createTypeChecker = (typeNames, overrides = {}) => {
|
|
|
12
12
|
const {
|
|
13
13
|
instrumentCoverage = _instrument,
|
|
14
14
|
} = overrides;
|
|
15
|
+
|
|
15
16
|
const tuples = parseTypeNames(typeNames);
|
|
16
17
|
const typeChecker = (path, options) => {
|
|
17
18
|
for (const [index, [operation, typeName]] of tuples.entries()) {
|
package/package.json
CHANGED