@putout/printer 18.2.9 → 18.2.11
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,16 @@
|
|
|
1
|
+
2026.03.08, v18.2.11
|
|
2
|
+
|
|
3
|
+
feature:
|
|
4
|
+
- b16bb59 @putout/printer: ArrayExpression: newline: isNewlineAfterComma
|
|
5
|
+
- 5f0e329 @putout/printer: @putout/plugin-minify v12.0.0
|
|
6
|
+
|
|
7
|
+
2026.03.08, v18.2.10
|
|
8
|
+
|
|
9
|
+
feature:
|
|
10
|
+
- 7a73310 @putout/printer: ArrayExpresison: maybeSecondIndent
|
|
11
|
+
- cfcf1ce @putout/printer: ArrayExpression: isSecondIndent
|
|
12
|
+
- 0acb26a @putout/printer: ArrayExpression: isSecondIndent
|
|
13
|
+
|
|
1
14
|
2026.03.08, v18.2.9
|
|
2
15
|
|
|
3
16
|
feature:
|
|
@@ -4,22 +4,19 @@ import {
|
|
|
4
4
|
isCoupleLines,
|
|
5
5
|
isStringAndIdentifier,
|
|
6
6
|
isIdentifierAndIdentifier,
|
|
7
|
-
isStringAndArray,
|
|
8
7
|
isSimpleAndNotEmptyObject,
|
|
9
|
-
isNextObject,
|
|
10
8
|
callWithNext,
|
|
11
|
-
isInsideArray,
|
|
12
9
|
callWithPrev,
|
|
13
10
|
} from '#is';
|
|
14
11
|
import {
|
|
15
12
|
isCurrentNewLine,
|
|
16
13
|
isMultiLine,
|
|
14
|
+
isNewlineAfterComma,
|
|
17
15
|
} from './newline.js';
|
|
18
16
|
import {isObjectAfterSimple} from './is-object-after-simple.js';
|
|
19
17
|
import {
|
|
20
|
-
isArrayInsideArray,
|
|
21
|
-
isHideIndent,
|
|
22
18
|
isNeedIndent,
|
|
19
|
+
maybeSecondIndent,
|
|
23
20
|
} from './indent.js';
|
|
24
21
|
import {
|
|
25
22
|
beforeIf,
|
|
@@ -30,35 +27,9 @@ const {
|
|
|
30
27
|
isObjectExpression,
|
|
31
28
|
isSpreadElement,
|
|
32
29
|
isIdentifier,
|
|
33
|
-
isFunction,
|
|
34
30
|
isCallExpression,
|
|
35
|
-
isObjectProperty,
|
|
36
31
|
} = types;
|
|
37
32
|
|
|
38
|
-
const isSpreadBeforeObject = (a) => {
|
|
39
|
-
if (!a.isObjectExpression())
|
|
40
|
-
return false;
|
|
41
|
-
|
|
42
|
-
const prev = a.getPrevSibling();
|
|
43
|
-
|
|
44
|
-
if (!prev.isSpreadElement())
|
|
45
|
-
return false;
|
|
46
|
-
|
|
47
|
-
const argCall = prev.get('argument');
|
|
48
|
-
|
|
49
|
-
if (argCall.isCallExpression()) {
|
|
50
|
-
const [first] = argCall.get('arguments');
|
|
51
|
-
|
|
52
|
-
if (isFunction(first))
|
|
53
|
-
return false;
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
if (prev.getPrevSibling().isObjectExpression())
|
|
57
|
-
return false;
|
|
58
|
-
|
|
59
|
-
return prev.get('argument').isCallExpression();
|
|
60
|
-
};
|
|
61
|
-
|
|
62
33
|
const isSimpleBetweenObjects = createTypeChecker([
|
|
63
34
|
['+', callWithNext(isObjectExpression)],
|
|
64
35
|
['-', isSpreadElement],
|
|
@@ -76,7 +47,9 @@ export const ArrayExpression = {
|
|
|
76
47
|
before(path, {print}) {
|
|
77
48
|
print.breakline();
|
|
78
49
|
},
|
|
79
|
-
print(path,
|
|
50
|
+
print(path, printer, semantics) {
|
|
51
|
+
const {print, maybe} = printer;
|
|
52
|
+
|
|
80
53
|
const {
|
|
81
54
|
maxElementsInOneLine,
|
|
82
55
|
trailingComma,
|
|
@@ -113,30 +86,21 @@ export const ArrayExpression = {
|
|
|
113
86
|
if (index < n || trailingComma)
|
|
114
87
|
maybe.print(is, ',');
|
|
115
88
|
|
|
116
|
-
if (
|
|
117
|
-
|
|
89
|
+
if (is && isNewlineAfterComma(element))
|
|
90
|
+
print.newline();
|
|
118
91
|
|
|
119
92
|
maybe.print.space(is && isObjectAfterSimple(element));
|
|
120
93
|
|
|
121
94
|
if (!is && index < n) {
|
|
122
95
|
print(',');
|
|
123
|
-
|
|
124
|
-
if (isSpaceAfterComa(element))
|
|
125
|
-
print.space();
|
|
96
|
+
maybe.print.space(isSpaceAfterComa(element));
|
|
126
97
|
}
|
|
127
98
|
}
|
|
128
99
|
|
|
129
100
|
maybe.indent.dec(needIndent);
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
maybe.indent.dec(needsToHideIndent);
|
|
135
|
-
maybe.indent(needsNewline);
|
|
136
|
-
maybe.indent.inc(needsToHideIndent);
|
|
137
|
-
} else if (!isArrayInsideArray(path) && !isObjectExpression(elements.at(-1))) {
|
|
138
|
-
maybe.indent(needsNewline);
|
|
139
|
-
}
|
|
101
|
+
maybeSecondIndent(path, printer, semantics, {
|
|
102
|
+
needsNewline,
|
|
103
|
+
});
|
|
140
104
|
|
|
141
105
|
if (isSimpleAndNotEmptyObject(path) && !isSpreadElement(elements.at(-1)) && !isCallExpression(elements.at(-1))) {
|
|
142
106
|
print(',');
|
|
@@ -1,6 +1,10 @@
|
|
|
1
1
|
import {types} from '@putout/babel';
|
|
2
|
-
import {isInsideArray, isInsideCall} from '#is';
|
|
3
2
|
import {createTypeChecker} from '#type-checker';
|
|
3
|
+
import {
|
|
4
|
+
isInsideArray,
|
|
5
|
+
isInsideCall,
|
|
6
|
+
isStringAndArray,
|
|
7
|
+
} from '#is';
|
|
4
8
|
|
|
5
9
|
const isTwoLongStrings = (path) => {
|
|
6
10
|
const [a, b] = path.node.elements;
|
|
@@ -93,5 +97,36 @@ export function isArrayInsideArray(path) {
|
|
|
93
97
|
const isTwo = (a) => a === 2;
|
|
94
98
|
|
|
95
99
|
export const isHideIndent = createTypeChecker([
|
|
100
|
+
['-: -> !', isInsideArray],
|
|
101
|
+
['-: parentPath -> !', isStringAndArray],
|
|
96
102
|
['+: parentPath.node.elements.length', isTwo],
|
|
97
103
|
]);
|
|
104
|
+
|
|
105
|
+
const isLastElementObjectExpression = ({node}) => isObjectExpression(node.elements.at(-1));
|
|
106
|
+
|
|
107
|
+
const isNeedsNewlineOption = (a, {needsNewline}) => needsNewline;
|
|
108
|
+
const isNeedsToHideIndentOption = (a, {needsToHideIndent}) => needsToHideIndent;
|
|
109
|
+
|
|
110
|
+
export const isSecondIndent = createTypeChecker([
|
|
111
|
+
['-: -> !', isNeedsNewlineOption],
|
|
112
|
+
['+', isNeedsToHideIndentOption],
|
|
113
|
+
['-: ->', isArrayInsideArray],
|
|
114
|
+
['+: -> !', isLastElementObjectExpression],
|
|
115
|
+
]);
|
|
116
|
+
|
|
117
|
+
export function maybeSecondIndent(path, printer, semantics, options) {
|
|
118
|
+
const {maybe, indent} = printer;
|
|
119
|
+
const {needsNewline} = options;
|
|
120
|
+
const needsToHideIndent = isHideIndent(path);
|
|
121
|
+
|
|
122
|
+
const needsToMakeSecondIndent = isSecondIndent(path, {
|
|
123
|
+
needsNewline,
|
|
124
|
+
needsToHideIndent,
|
|
125
|
+
});
|
|
126
|
+
|
|
127
|
+
if (needsToMakeSecondIndent) {
|
|
128
|
+
maybe.indent.dec(needsToHideIndent);
|
|
129
|
+
indent();
|
|
130
|
+
maybe.indent.inc(needsToHideIndent);
|
|
131
|
+
}
|
|
132
|
+
}
|
|
@@ -11,6 +11,7 @@ import {
|
|
|
11
11
|
isSimpleAndNotEmptyObject,
|
|
12
12
|
isInsideCall,
|
|
13
13
|
isInsideArray,
|
|
14
|
+
isNextObject,
|
|
14
15
|
} from '#is';
|
|
15
16
|
import {isIncreaseIndent} from './indent.js';
|
|
16
17
|
|
|
@@ -309,3 +310,8 @@ export const isCurrentNewLine = createTypeChecker([
|
|
|
309
310
|
'+: -> SpreadElement',
|
|
310
311
|
'+: -> !ObjectExpression',
|
|
311
312
|
]);
|
|
313
|
+
|
|
314
|
+
export const isNewlineAfterComma = createTypeChecker([
|
|
315
|
+
['-', isNextObject],
|
|
316
|
+
['+: -> !', isObjectExpression],
|
|
317
|
+
]);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@putout/printer",
|
|
3
|
-
"version": "18.2.
|
|
3
|
+
"version": "18.2.11",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"author": "coderaiser <mnemonic.enemy@gmail.com> (https://github.com/coderaiser)",
|
|
6
6
|
"description": "Simplest possible opinionated Babel AST printer for 🐊Putout",
|
|
@@ -74,7 +74,6 @@
|
|
|
74
74
|
"@babel/parser": "^7.28.5",
|
|
75
75
|
"@putout/eslint": "^6.0.0",
|
|
76
76
|
"@putout/eslint-flat": "^4.0.0",
|
|
77
|
-
"@putout/plugin-minify": "^11.2.1",
|
|
78
77
|
"@putout/plugin-printer": "^8.0.0",
|
|
79
78
|
"@putout/plugin-promises": "^19.0.0",
|
|
80
79
|
"@putout/plugin-react-hook-form": "^6.0.0",
|