@putout/printer 18.1.1 → 18.1.3
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 +13 -0
- package/lib/tokenize/expressions/array-expression/array-expression.js +19 -31
- package/lib/tokenize/expressions/array-expression/before-if.js +24 -0
- package/lib/tokenize/expressions/array-expression/indent.js +1 -3
- package/lib/tokenize/expressions/array-expression/is-object-after-simple.js +0 -6
- package/lib/tokenize/expressions/array-expression/newline.js +6 -3
- package/lib/tokenize/expressions/member-expression/is-looks-like-chain.js +1 -0
- package/lib/tokenize/expressions/object-expression/object-expression.js +2 -0
- package/lib/tokenize/is.js +1 -0
- package/lib/tokenize/statements/expression-statement/expression-statement.js +0 -1
- package/lib/tokenize/type-checker/parsers.js +1 -1
- package/package.json +1 -1
package/ChangeLog
CHANGED
|
@@ -1,3 +1,16 @@
|
|
|
1
|
+
2026.03.06, v18.1.3
|
|
2
|
+
|
|
3
|
+
fix:
|
|
4
|
+
- 033b2a6 @putout/printer: ArrayExpression: maxElementLengthInOneLine
|
|
5
|
+
|
|
6
|
+
2026.03.06, v18.1.2
|
|
7
|
+
|
|
8
|
+
feature:
|
|
9
|
+
- 5996fbf @putout/printer: TypeChecker: ->
|
|
10
|
+
- 7001376 @putout/printer: ArrayExpression: beforeIf: move out
|
|
11
|
+
- 2f22d1d @putout/printer: ArrayExpression: isSimpleBetweenObjects
|
|
12
|
+
- 50166f4 @putout/printer: ArrayExpression: isSpaceAfterComma
|
|
13
|
+
|
|
1
14
|
2026.03.06, v18.1.1
|
|
2
15
|
|
|
3
16
|
feature:
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import {types} from '@putout/babel';
|
|
2
|
+
import {createTypeChecker} from '#type-checker';
|
|
2
3
|
import {
|
|
3
4
|
isCoupleLines,
|
|
4
5
|
isStringAndIdentifier,
|
|
@@ -6,6 +7,8 @@ import {
|
|
|
6
7
|
isStringAndArray,
|
|
7
8
|
isSimpleAndNotEmptyObject,
|
|
8
9
|
isNextObject,
|
|
10
|
+
getNext,
|
|
11
|
+
isInsideArray,
|
|
9
12
|
} from '#is';
|
|
10
13
|
import {
|
|
11
14
|
isIncreaseIndent,
|
|
@@ -13,14 +16,14 @@ import {
|
|
|
13
16
|
isMultiLine,
|
|
14
17
|
} from './newline.js';
|
|
15
18
|
import {
|
|
16
|
-
isInsideArray,
|
|
17
19
|
isArrayInsideArray,
|
|
18
20
|
isArrayIndented,
|
|
19
21
|
} from './indent.js';
|
|
22
|
+
import {isObjectAfterSimple} from './is-object-after-simple.js';
|
|
20
23
|
import {
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
} from './
|
|
24
|
+
beforeIf,
|
|
25
|
+
isInsideOneElementArray,
|
|
26
|
+
} from './before-if.js';
|
|
24
27
|
|
|
25
28
|
const {
|
|
26
29
|
isObjectExpression,
|
|
@@ -60,35 +63,20 @@ const isSpreadBeforeObject = (a) => {
|
|
|
60
63
|
return prev.get('argument').isCallExpression();
|
|
61
64
|
};
|
|
62
65
|
|
|
63
|
-
const
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
return next
|
|
71
|
-
.getNextSibling()
|
|
72
|
-
.isObjectExpression();
|
|
73
|
-
};
|
|
66
|
+
const isSimpleBetweenObjects = createTypeChecker([
|
|
67
|
+
['+', getNext(isObjectExpression)],
|
|
68
|
+
['-', isSpreadElement],
|
|
69
|
+
['-', isIdentifier],
|
|
70
|
+
['+: -> !', isCallExpression],
|
|
71
|
+
]);
|
|
74
72
|
|
|
75
|
-
const
|
|
73
|
+
const isSpaceAfterComa = createTypeChecker([
|
|
74
|
+
getNext(isSimpleBetweenObjects),
|
|
75
|
+
'+: -> !ObjectExpression',
|
|
76
|
+
]);
|
|
76
77
|
|
|
77
78
|
export const ArrayExpression = {
|
|
78
|
-
beforeIf
|
|
79
|
-
const {parentPath} = path;
|
|
80
|
-
|
|
81
|
-
if (!parentPath.isArrayExpression())
|
|
82
|
-
return false;
|
|
83
|
-
|
|
84
|
-
if (isCoupleLines(parentPath))
|
|
85
|
-
return false;
|
|
86
|
-
|
|
87
|
-
if (isStringAndIdentifier(path) && isInsideOneElementArray(path))
|
|
88
|
-
return true;
|
|
89
|
-
|
|
90
|
-
return isIdentifierAndIdentifier(path);
|
|
91
|
-
},
|
|
79
|
+
beforeIf,
|
|
92
80
|
before(path, {print}) {
|
|
93
81
|
print.breakline();
|
|
94
82
|
},
|
|
@@ -137,7 +125,7 @@ export const ArrayExpression = {
|
|
|
137
125
|
if (!is && index < n) {
|
|
138
126
|
print(',');
|
|
139
127
|
|
|
140
|
-
if (
|
|
128
|
+
if (isSpaceAfterComa(element))
|
|
141
129
|
print.space();
|
|
142
130
|
}
|
|
143
131
|
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import {createTypeChecker} from '#type-checker';
|
|
2
|
+
import {
|
|
3
|
+
isCoupleLines,
|
|
4
|
+
isIdentifierAndIdentifier,
|
|
5
|
+
isInsideArray,
|
|
6
|
+
isStringAndIdentifier,
|
|
7
|
+
} from '#is';
|
|
8
|
+
|
|
9
|
+
export const isInsideOneElementArray = ({parentPath}) => {
|
|
10
|
+
const {elements} = parentPath.node;
|
|
11
|
+
return elements.length === 1;
|
|
12
|
+
};
|
|
13
|
+
|
|
14
|
+
const isStringAndIdentifierInsideOneElementArray = createTypeChecker([
|
|
15
|
+
['-: -> !', isStringAndIdentifier],
|
|
16
|
+
['+', isInsideOneElementArray],
|
|
17
|
+
]);
|
|
18
|
+
|
|
19
|
+
export const beforeIf = createTypeChecker([
|
|
20
|
+
['-: -> !', isInsideArray],
|
|
21
|
+
['-: parentPath ->', isCoupleLines],
|
|
22
|
+
isIdentifierAndIdentifier,
|
|
23
|
+
isStringAndIdentifierInsideOneElementArray,
|
|
24
|
+
]);
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import {types} from '@putout/babel';
|
|
2
|
-
import {isIndented} from '#is';
|
|
2
|
+
import {isIndented, isInsideArray} from '#is';
|
|
3
3
|
|
|
4
4
|
const {
|
|
5
5
|
isStringLiteral,
|
|
@@ -8,8 +8,6 @@ const {
|
|
|
8
8
|
isTemplateLiteral,
|
|
9
9
|
} = types;
|
|
10
10
|
|
|
11
|
-
export const isInsideArray = (path) => path.parentPath.isArrayExpression();
|
|
12
|
-
|
|
13
11
|
const isObjectAfterString = ([first, second]) => {
|
|
14
12
|
if (!first || !second)
|
|
15
13
|
return false;
|
|
@@ -10,8 +10,8 @@ import {
|
|
|
10
10
|
isIdentifierAndIdentifier,
|
|
11
11
|
isSimpleAndNotEmptyObject,
|
|
12
12
|
isInsideCall,
|
|
13
|
+
isInsideArray,
|
|
13
14
|
} from '#is';
|
|
14
|
-
import {isInsideArray} from './indent.js';
|
|
15
15
|
import {isInsideForOf} from '../object-pattern/is.js';
|
|
16
16
|
|
|
17
17
|
const isLastArg = ({parentPath}) => !parentPath.isCallExpression();
|
|
@@ -151,10 +151,13 @@ const isMoreThenMaxLiteralLength = (path, {maxElementLengthInOneLine}) => {
|
|
|
151
151
|
return first.value.length > maxElementLengthInOneLine;
|
|
152
152
|
};
|
|
153
153
|
|
|
154
|
-
const isMoreThenMaxIdentifierLength = (path) => {
|
|
154
|
+
const isMoreThenMaxIdentifierLength = (path, {maxElementLengthInOneLine}) => {
|
|
155
155
|
const [first] = path.node.elements;
|
|
156
156
|
|
|
157
|
-
|
|
157
|
+
if (!isIdentifier(first))
|
|
158
|
+
return false;
|
|
159
|
+
|
|
160
|
+
return first.name.length > maxElementLengthInOneLine;
|
|
158
161
|
};
|
|
159
162
|
|
|
160
163
|
const isMoreThenMaxElementLengthInOneLine = createTypeChecker([
|
|
@@ -38,10 +38,12 @@ const {
|
|
|
38
38
|
} = types;
|
|
39
39
|
|
|
40
40
|
const isLogicalArgument = (path) => isLogicalExpression(path.node.argument);
|
|
41
|
+
|
|
41
42
|
const isParens = createTypeChecker([
|
|
42
43
|
isInsideBody,
|
|
43
44
|
isInsideExpression,
|
|
44
45
|
]);
|
|
46
|
+
|
|
45
47
|
const getCallee = (fn) => (a) => fn(a.get('callee'));
|
|
46
48
|
|
|
47
49
|
const isMemberExpressionCallee = createTypeChecker([
|
package/lib/tokenize/is.js
CHANGED
|
@@ -24,6 +24,7 @@ export const isInsideBlock = (path) => isBlockStatement(path.parentPath);
|
|
|
24
24
|
export const isInsideSwitchCase = (path) => isSwitchCase(path.parentPath);
|
|
25
25
|
export const isInsideBody = ({node, parentPath}) => node === parentPath.node.body;
|
|
26
26
|
export const isInsideExpression = ({parentPath}) => isExpressionStatement(parentPath);
|
|
27
|
+
export const isInsideArray = (path) => isArrayExpression(path.parentPath);
|
|
27
28
|
|
|
28
29
|
export const isInsideTSModuleBlock = ({parentPath}) => isTSModuleBlock(parentPath);
|
|
29
30
|
|
package/package.json
CHANGED