@putout/printer 18.8.5 → 18.9.0
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,14 @@
|
|
|
1
|
+
2026.03.20, v18.9.0
|
|
2
|
+
|
|
3
|
+
feature:
|
|
4
|
+
- 2840175e @putout/printer: JSXElement: apply type-checker
|
|
5
|
+
- 2c116629 @putout/printer: JSXElement: indent
|
|
6
|
+
|
|
7
|
+
2026.03.20, v18.8.6
|
|
8
|
+
|
|
9
|
+
feature:
|
|
10
|
+
- 9e0406e2 @putout/printer: type-checker: maybeCutOptions
|
|
11
|
+
|
|
1
12
|
2026.03.20, v18.8.5
|
|
2
13
|
|
|
3
14
|
feature:
|
|
@@ -32,13 +32,10 @@ function hasPropertyLeadingComment(path) {
|
|
|
32
32
|
return false;
|
|
33
33
|
}
|
|
34
34
|
|
|
35
|
-
const cutOptions = (fn) => (a) => fn(a);
|
|
36
|
-
const isFunctionLike = cutOptions(isFunction);
|
|
37
|
-
|
|
38
35
|
const isFunctionParam = callWithParent(createTypeChecker([
|
|
39
|
-
['+',
|
|
36
|
+
['+', isFunction],
|
|
40
37
|
['-: -> !AssignmentPattern'],
|
|
41
|
-
['+: parentPath',
|
|
38
|
+
['+: parentPath', isFunction],
|
|
42
39
|
]));
|
|
43
40
|
|
|
44
41
|
const isOneOfIdentifiersHasMoreLength = createTypeChecker([
|
|
@@ -68,7 +65,9 @@ function isCoupleAssigns(path) {
|
|
|
68
65
|
if (isFunctionParam(path))
|
|
69
66
|
return false;
|
|
70
67
|
|
|
71
|
-
const properties = path
|
|
68
|
+
const properties = path
|
|
69
|
+
.node
|
|
70
|
+
.properties
|
|
72
71
|
.filter(isObjectProperty)
|
|
73
72
|
.map(getValue)
|
|
74
73
|
.filter(isAssignmentPattern);
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import {types} from '@putout/babel';
|
|
2
|
+
import {createTypeChecker} from '#type-checker';
|
|
3
|
+
|
|
4
|
+
const {isFunction} = types;
|
|
5
|
+
|
|
6
|
+
export function isNeedIndent(path) {
|
|
7
|
+
if (hasComplexAttribute(path))
|
|
8
|
+
return false;
|
|
9
|
+
|
|
10
|
+
const insideFn = path.parentPath.isArrowFunctionExpression();
|
|
11
|
+
const insideJSX = path.parentPath.isJSXElement();
|
|
12
|
+
const insideCall = path.parentPath.parentPath.isCallExpression();
|
|
13
|
+
|
|
14
|
+
return insideJSX || insideFn && insideCall;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
const isComplexAttribute = createTypeChecker([
|
|
18
|
+
['+: -> JSXSpreadAttribute'],
|
|
19
|
+
['-: node.value -> !JSXExpressionContainer'],
|
|
20
|
+
['+: parentPath.node.attributes.length', '>', 1],
|
|
21
|
+
['+: node.value.expression', isFunction],
|
|
22
|
+
]);
|
|
23
|
+
|
|
24
|
+
function hasComplexAttribute(path) {
|
|
25
|
+
const attributes = path.get('openingElement.attributes');
|
|
26
|
+
|
|
27
|
+
for (const attribute of attributes) {
|
|
28
|
+
if (isComplexAttribute(attribute))
|
|
29
|
+
return true;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
return false;
|
|
33
|
+
}
|
|
@@ -1,13 +1,25 @@
|
|
|
1
1
|
import {types} from '@putout/babel';
|
|
2
|
+
import {createTypeChecker} from '#type-checker';
|
|
3
|
+
import {isNeedIndent} from './indent.js';
|
|
4
|
+
|
|
5
|
+
const isDeeplyNestedJSX = ({parentPath}) => {
|
|
6
|
+
return isJSXElement(parentPath.parentPath?.parentPath?.parentPath);
|
|
7
|
+
};
|
|
8
|
+
|
|
9
|
+
const condition = createTypeChecker([
|
|
10
|
+
'+: node.extra.parenthesized -> +',
|
|
11
|
+
'+: parentPath -> ReturnStatement',
|
|
12
|
+
'+: parentPath -> ParenthesizedExpression',
|
|
13
|
+
'+: parentPath -> ArrowFunctionExpression',
|
|
14
|
+
'+: parentPath -> VariableDeclarator',
|
|
15
|
+
]);
|
|
2
16
|
|
|
3
17
|
const {
|
|
4
18
|
isJSXElement,
|
|
5
|
-
|
|
6
|
-
isFunction,
|
|
7
|
-
isJSXSpreadAttribute,
|
|
19
|
+
isArrowFunctionExpression,
|
|
8
20
|
} = types;
|
|
9
21
|
|
|
10
|
-
const isInsideArrow = ({parentPath}) =>
|
|
22
|
+
const isInsideArrow = ({parentPath}) => isArrowFunctionExpression(parentPath);
|
|
11
23
|
|
|
12
24
|
export const JSXElement = {
|
|
13
25
|
condition,
|
|
@@ -36,7 +48,7 @@ export const JSXElement = {
|
|
|
36
48
|
},
|
|
37
49
|
after(path, {write, indent, maybe}) {
|
|
38
50
|
const {leadingComments} = path.node;
|
|
39
|
-
const isJSX =
|
|
51
|
+
const isJSX = isDeeplyNestedJSX(path);
|
|
40
52
|
|
|
41
53
|
if (isJSX) {
|
|
42
54
|
write.breakline();
|
|
@@ -49,51 +61,3 @@ export const JSXElement = {
|
|
|
49
61
|
maybe.write(!leadingComments?.length, ')');
|
|
50
62
|
},
|
|
51
63
|
};
|
|
52
|
-
|
|
53
|
-
function condition(path) {
|
|
54
|
-
if (path.parentPath.isReturnStatement())
|
|
55
|
-
return true;
|
|
56
|
-
|
|
57
|
-
if (path.parentPath.isParenthesizedExpression())
|
|
58
|
-
return true;
|
|
59
|
-
|
|
60
|
-
if (path.node.extra?.parenthesized)
|
|
61
|
-
return true;
|
|
62
|
-
|
|
63
|
-
if (path.parentPath.isArrowFunctionExpression())
|
|
64
|
-
return true;
|
|
65
|
-
|
|
66
|
-
return path.parentPath.isVariableDeclarator();
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
function hasComplexAttribute(path) {
|
|
70
|
-
const {attributes} = path.node.openingElement;
|
|
71
|
-
|
|
72
|
-
for (const attribute of attributes) {
|
|
73
|
-
const {value} = attribute;
|
|
74
|
-
|
|
75
|
-
if (isJSXSpreadAttribute(attribute))
|
|
76
|
-
return true;
|
|
77
|
-
|
|
78
|
-
if (!isJSXExpressionContainer(value))
|
|
79
|
-
continue;
|
|
80
|
-
|
|
81
|
-
const {expression} = value;
|
|
82
|
-
|
|
83
|
-
if (isFunction(expression))
|
|
84
|
-
return true;
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
return false;
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
function isNeedIndent(path) {
|
|
91
|
-
if (hasComplexAttribute(path))
|
|
92
|
-
return false;
|
|
93
|
-
|
|
94
|
-
const insideFn = path.parentPath.isArrowFunctionExpression();
|
|
95
|
-
const insideJSX = path.parentPath.isJSXElement();
|
|
96
|
-
const insideCall = path.parentPath.parentPath.isCallExpression();
|
|
97
|
-
|
|
98
|
-
return insideJSX || insideFn && insideCall;
|
|
99
|
-
}
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import {types} from '@putout/babel';
|
|
2
|
+
|
|
1
3
|
const isFn = (a) => typeof a === 'function';
|
|
2
4
|
const isString = (a) => typeof a === 'string';
|
|
3
5
|
const maybeNot = (not, a) => not ? !a : a;
|
|
@@ -18,10 +20,19 @@ export const maybeCall = (fn, not, a, options) => {
|
|
|
18
20
|
if (!isFn(fn))
|
|
19
21
|
return false;
|
|
20
22
|
|
|
21
|
-
const result = fn
|
|
23
|
+
const result = maybeCutOptions(fn, a, options);
|
|
22
24
|
|
|
23
25
|
if (not)
|
|
24
26
|
return !result;
|
|
25
27
|
|
|
26
28
|
return result;
|
|
27
29
|
};
|
|
30
|
+
|
|
31
|
+
function maybeCutOptions(fn, a, options) {
|
|
32
|
+
const {name} = fn;
|
|
33
|
+
|
|
34
|
+
if (types[name] === fn)
|
|
35
|
+
return fn(a);
|
|
36
|
+
|
|
37
|
+
return fn(a, options);
|
|
38
|
+
}
|
package/package.json
CHANGED