@putout/printer 18.2.7 → 18.2.9
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
|
@@ -15,12 +15,12 @@ import {
|
|
|
15
15
|
isCurrentNewLine,
|
|
16
16
|
isMultiLine,
|
|
17
17
|
} from './newline.js';
|
|
18
|
+
import {isObjectAfterSimple} from './is-object-after-simple.js';
|
|
18
19
|
import {
|
|
19
20
|
isArrayInsideArray,
|
|
20
|
-
|
|
21
|
-
|
|
21
|
+
isHideIndent,
|
|
22
|
+
isNeedIndent,
|
|
22
23
|
} from './indent.js';
|
|
23
|
-
import {isObjectAfterSimple} from './is-object-after-simple.js';
|
|
24
24
|
import {
|
|
25
25
|
beforeIf,
|
|
26
26
|
isInsideOneElementArray,
|
|
@@ -29,17 +29,12 @@ import {
|
|
|
29
29
|
const {
|
|
30
30
|
isObjectExpression,
|
|
31
31
|
isSpreadElement,
|
|
32
|
-
isStringLiteral,
|
|
33
32
|
isIdentifier,
|
|
34
33
|
isFunction,
|
|
35
34
|
isCallExpression,
|
|
36
35
|
isObjectProperty,
|
|
37
36
|
} = types;
|
|
38
37
|
|
|
39
|
-
const isNextString = (path) => isStringLiteral(path.getNextSibling());
|
|
40
|
-
const isPrevString = (path) => isStringLiteral(path.getPrevSibling());
|
|
41
|
-
const isAroundStrings = (path) => isNextString(path) || isPrevString(path);
|
|
42
|
-
|
|
43
38
|
const isSpreadBeforeObject = (a) => {
|
|
44
39
|
if (!a.isObjectExpression())
|
|
45
40
|
return false;
|
|
@@ -89,13 +84,12 @@ export const ArrayExpression = {
|
|
|
89
84
|
} = semantics;
|
|
90
85
|
|
|
91
86
|
const elements = path.get('elements');
|
|
92
|
-
const shouldIncreaseIndent = !isIncreaseIndent(path);
|
|
93
87
|
|
|
94
88
|
print('[');
|
|
95
89
|
|
|
96
|
-
const
|
|
90
|
+
const needIndent = isNeedIndent(path);
|
|
97
91
|
|
|
98
|
-
maybe.indent.inc(
|
|
92
|
+
maybe.indent.inc(needIndent);
|
|
99
93
|
|
|
100
94
|
const needsNewline = isMultiLine(path, {
|
|
101
95
|
maxElementsInOneLine,
|
|
@@ -132,19 +126,16 @@ export const ArrayExpression = {
|
|
|
132
126
|
}
|
|
133
127
|
}
|
|
134
128
|
|
|
135
|
-
maybe.indent.dec(
|
|
136
|
-
|
|
137
|
-
const parentElements = path.parentPath.get('elements');
|
|
129
|
+
maybe.indent.dec(needIndent);
|
|
138
130
|
|
|
139
131
|
if (isInsideArray(path) && isStringAndArray(path.parentPath)) {
|
|
140
|
-
const
|
|
141
|
-
const isHideIdent = !isAroundStrings(path) || parentCountTwo;
|
|
132
|
+
const needsToHideIndent = isHideIndent(path);
|
|
142
133
|
|
|
143
|
-
maybe.indent.dec(
|
|
144
|
-
maybe.indent(
|
|
145
|
-
maybe.indent.inc(
|
|
134
|
+
maybe.indent.dec(needsToHideIndent);
|
|
135
|
+
maybe.indent(needsNewline);
|
|
136
|
+
maybe.indent.inc(needsToHideIndent);
|
|
146
137
|
} else if (!isArrayInsideArray(path) && !isObjectExpression(elements.at(-1))) {
|
|
147
|
-
maybe.indent(
|
|
138
|
+
maybe.indent(needsNewline);
|
|
148
139
|
}
|
|
149
140
|
|
|
150
141
|
if (isSimpleAndNotEmptyObject(path) && !isSpreadElement(elements.at(-1)) && !isCallExpression(elements.at(-1))) {
|
|
@@ -53,13 +53,6 @@ const isObjectAfterString = (path) => {
|
|
|
53
53
|
return isTemplateLiteral(first);
|
|
54
54
|
};
|
|
55
55
|
|
|
56
|
-
export const isIndentElement = createTypeChecker([
|
|
57
|
-
['-', isArrayInsideArray],
|
|
58
|
-
['-', isObjectAfterString],
|
|
59
|
-
['+: -> !', isTwoLongStrings],
|
|
60
|
-
['+: -> !', isInsideArray],
|
|
61
|
-
]);
|
|
62
|
-
|
|
63
56
|
export const isIncreaseIndent = createTypeChecker([
|
|
64
57
|
['-: node.elements.length -> !', Boolean],
|
|
65
58
|
['+', isBooleanAndObject],
|
|
@@ -69,6 +62,18 @@ export const isIncreaseIndent = createTypeChecker([
|
|
|
69
62
|
['+', isStringAndObject],
|
|
70
63
|
]);
|
|
71
64
|
|
|
65
|
+
export const isIndentElement = createTypeChecker([
|
|
66
|
+
['-', isArrayInsideArray],
|
|
67
|
+
['-', isObjectAfterString],
|
|
68
|
+
['+: -> !', isTwoLongStrings],
|
|
69
|
+
['+: -> !', isInsideArray],
|
|
70
|
+
]);
|
|
71
|
+
|
|
72
|
+
export const isNeedIndent = createTypeChecker([
|
|
73
|
+
['-: -> !', isIndentElement],
|
|
74
|
+
['+: -> !', isIncreaseIndent],
|
|
75
|
+
]);
|
|
76
|
+
|
|
72
77
|
export function isArrayInsideArray(path) {
|
|
73
78
|
if (!path.isArrayExpression() || !path.parentPath.isArrayExpression())
|
|
74
79
|
return false;
|
|
@@ -85,3 +90,8 @@ export function isArrayInsideArray(path) {
|
|
|
85
90
|
return length <= 3 && length !== 1;
|
|
86
91
|
}
|
|
87
92
|
|
|
93
|
+
const isTwo = (a) => a === 2;
|
|
94
|
+
|
|
95
|
+
export const isHideIndent = createTypeChecker([
|
|
96
|
+
['+: parentPath.node.elements.length', isTwo],
|
|
97
|
+
]);
|
package/package.json
CHANGED