@putout/printer 18.3.0 → 18.3.1
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 +5 -0
- package/lib/tokenize/expressions/array-expression/after-if.js +0 -1
- package/lib/tokenize/expressions/array-expression/array-expression.js +13 -7
- package/lib/tokenize/expressions/array-expression/breakline.js +16 -0
- package/lib/tokenize/expressions/array-expression/comma.js +12 -9
- package/lib/tokenize/expressions/array-expression/is.js +2 -0
- package/lib/tokenize/expressions/array-expression/newline.js +0 -1
- package/package.json +1 -1
package/ChangeLog
CHANGED
|
@@ -12,10 +12,11 @@ import {
|
|
|
12
12
|
import {beforeIf} from './before-if.js';
|
|
13
13
|
import {afterIf} from './after-if.js';
|
|
14
14
|
import {
|
|
15
|
-
|
|
15
|
+
isCommaAfterElement,
|
|
16
16
|
isNewlineAfterComma,
|
|
17
17
|
isSpaceAfterComa,
|
|
18
18
|
} from './comma.js';
|
|
19
|
+
import {isBreaklineBeforeClosingSquareBrace} from './breakline.js';
|
|
19
20
|
|
|
20
21
|
const {isObjectExpression} = types;
|
|
21
22
|
|
|
@@ -38,6 +39,7 @@ export const ArrayExpression = {
|
|
|
38
39
|
} = semantics;
|
|
39
40
|
|
|
40
41
|
const needIndent = isNeedIndent(path);
|
|
42
|
+
|
|
41
43
|
const multiline = isMultiLine(path, {
|
|
42
44
|
maxElementsInOneLine,
|
|
43
45
|
maxElementLengthInOneLine,
|
|
@@ -53,8 +55,15 @@ export const ArrayExpression = {
|
|
|
53
55
|
|
|
54
56
|
for (const [index, element] of elements.entries()) {
|
|
55
57
|
const isLast = index === n;
|
|
56
|
-
const needsIndentBeforeElement = isIndentBeforeElement(element, {
|
|
57
|
-
|
|
58
|
+
const needsIndentBeforeElement = isIndentBeforeElement(element, {
|
|
59
|
+
multiline,
|
|
60
|
+
});
|
|
61
|
+
|
|
62
|
+
const needsComma = isCommaAfterElement(path, {
|
|
63
|
+
trailingComma,
|
|
64
|
+
isLast,
|
|
65
|
+
needsIndentBeforeElement,
|
|
66
|
+
});
|
|
58
67
|
|
|
59
68
|
if (isNewlineBeforeElement(element))
|
|
60
69
|
print.newline();
|
|
@@ -81,10 +90,8 @@ export const ArrayExpression = {
|
|
|
81
90
|
multiline,
|
|
82
91
|
});
|
|
83
92
|
|
|
84
|
-
if (
|
|
85
|
-
print(',');
|
|
93
|
+
if (isBreaklineBeforeClosingSquareBrace(path))
|
|
86
94
|
print.breakline();
|
|
87
|
-
}
|
|
88
95
|
|
|
89
96
|
print(']');
|
|
90
97
|
},
|
|
@@ -107,4 +114,3 @@ const isNewlineBeforeElement = createTypeChecker([
|
|
|
107
114
|
['-', callWithNext(isObjectExpression)],
|
|
108
115
|
['+', callWithPrev(isObjectExpression)],
|
|
109
116
|
]);
|
|
110
|
-
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import {types} from '@putout/babel';
|
|
2
|
+
import {createTypeChecker} from '#type-checker';
|
|
3
|
+
import {isSimpleAndNotEmptyObject} from '#is';
|
|
4
|
+
|
|
5
|
+
const {
|
|
6
|
+
isSpreadElement,
|
|
7
|
+
isCallExpression,
|
|
8
|
+
} = types;
|
|
9
|
+
|
|
10
|
+
const callWithLastElement = (fn) => (a) => fn(a.at(-1));
|
|
11
|
+
|
|
12
|
+
export const isBreaklineBeforeClosingSquareBrace = createTypeChecker([
|
|
13
|
+
['-: -> !', isSimpleAndNotEmptyObject],
|
|
14
|
+
['-: node.elements', callWithLastElement(isSpreadElement)],
|
|
15
|
+
['+: node.elements -> !', callWithLastElement(isCallExpression)],
|
|
16
|
+
]);
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import {types} from '@putout/babel';
|
|
2
2
|
import {createTypeChecker} from '#type-checker';
|
|
3
|
-
import {
|
|
4
|
-
|
|
5
|
-
isSimpleAndNotEmptyObject,
|
|
6
|
-
} from '#is';
|
|
3
|
+
import {callWithNext} from '#is';
|
|
4
|
+
import {isBreaklineBeforeClosingSquareBrace} from './breakline.js';
|
|
7
5
|
import {
|
|
8
6
|
isLastOption,
|
|
9
7
|
isMultilineOption,
|
|
8
|
+
isNeedsIndentBeforeElementOption,
|
|
9
|
+
isTrailingCommaOption,
|
|
10
10
|
} from './is.js';
|
|
11
11
|
|
|
12
12
|
const {
|
|
@@ -16,12 +16,15 @@ const {
|
|
|
16
16
|
isIdentifier,
|
|
17
17
|
} = types;
|
|
18
18
|
|
|
19
|
-
const
|
|
19
|
+
const isCommaAfterElementByOption = createTypeChecker([
|
|
20
|
+
['+: -> !', isLastOption],
|
|
21
|
+
['-: -> !', isNeedsIndentBeforeElementOption],
|
|
22
|
+
['+', isTrailingCommaOption],
|
|
23
|
+
]);
|
|
20
24
|
|
|
21
|
-
export const
|
|
22
|
-
['
|
|
23
|
-
['
|
|
24
|
-
['+: node.elements -> !', callWithLastElement(isCallExpression)],
|
|
25
|
+
export const isCommaAfterElement = createTypeChecker([
|
|
26
|
+
['+', isCommaAfterElementByOption],
|
|
27
|
+
['+', isBreaklineBeforeClosingSquareBrace],
|
|
25
28
|
]);
|
|
26
29
|
|
|
27
30
|
export const isNewlineAfterComma = createTypeChecker([
|
|
@@ -2,3 +2,5 @@ export const isMultilineOption = (a, {multiline}) => multiline;
|
|
|
2
2
|
export const isNeedsToHideIndentOption = (a, {needsToHideIndent}) => needsToHideIndent;
|
|
3
3
|
export const isLastOption = (a, {isLast}) => isLast;
|
|
4
4
|
|
|
5
|
+
export const isTrailingCommaOption = (a, {trailingComma}) => trailingComma;
|
|
6
|
+
export const isNeedsIndentBeforeElementOption = (a, {needsIndentBeforeElement}) => needsIndentBeforeElement;
|
package/package.json
CHANGED