@putout/printer 18.47.5 → 18.48.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
|
@@ -3,7 +3,7 @@ import {parseComments} from '#comments';
|
|
|
3
3
|
|
|
4
4
|
export {JSXElement} from './jsx-element.js';
|
|
5
5
|
export {JSXAttribute} from './jsx-attribute.js';
|
|
6
|
-
export {JSXOpeningElement} from './jsx-opening-element.js';
|
|
6
|
+
export {JSXOpeningElement} from './jsx-opening-element/jsx-opening-element.js';
|
|
7
7
|
export * from './jsx-fragment.js';
|
|
8
8
|
export {JSXText} from './jsx-text/jsx-text.js';
|
|
9
9
|
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import {types} from '@putout/babel';
|
|
2
|
+
import {createTypeChecker} from '#type-checker';
|
|
3
|
+
import {isCoupleLines} from '#is';
|
|
4
|
+
|
|
5
|
+
const {
|
|
6
|
+
isObjectProperty,
|
|
7
|
+
isCallExpression,
|
|
8
|
+
isJSXElement,
|
|
9
|
+
isJSXExpressionContainer,
|
|
10
|
+
isJSXFragment,
|
|
11
|
+
isLogicalExpression,
|
|
12
|
+
isFunction,
|
|
13
|
+
} = types;
|
|
14
|
+
|
|
15
|
+
const isIdentableParent = createTypeChecker([
|
|
16
|
+
isObjectProperty,
|
|
17
|
+
isCallExpression,
|
|
18
|
+
isJSXElement,
|
|
19
|
+
isJSXExpressionContainer,
|
|
20
|
+
isJSXFragment,
|
|
21
|
+
isLogicalExpression,
|
|
22
|
+
]);
|
|
23
|
+
|
|
24
|
+
const hasJSXExpression = ({value}) => isJSXExpressionContainer(value);
|
|
25
|
+
|
|
26
|
+
const hasFnAttribute = (path) => {
|
|
27
|
+
for (const attribute of path.node.attributes.filter(hasJSXExpression)) {
|
|
28
|
+
if (isFunction(attribute.value.expression))
|
|
29
|
+
return true;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
return false;
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
export const isIndentBefore = createTypeChecker([
|
|
36
|
+
['+: parentPath.parentPath -> !', isIdentableParent],
|
|
37
|
+
['-: parentPath.parentPath -> !CallExpression'],
|
|
38
|
+
['+', hasFnAttribute],
|
|
39
|
+
]);
|
|
40
|
+
|
|
41
|
+
export const isIndent = createTypeChecker([
|
|
42
|
+
['-: -> !', isCoupleLines],
|
|
43
|
+
['+: parentPath.parentPath -> JSXElement'],
|
|
44
|
+
['+: parentPath.parentPath -> CallExpression'],
|
|
45
|
+
]);
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import {isCoupleLines} from '#is';
|
|
2
|
+
import {isIndent, isIndentBefore} from './indent.js';
|
|
3
|
+
|
|
4
|
+
export const JSXOpeningElement = (path, {print, maybe}) => {
|
|
5
|
+
const coupleLines = isCoupleLines(path);
|
|
6
|
+
const shouldIndent = isIndent(path);
|
|
7
|
+
|
|
8
|
+
maybe.indent.inc(shouldIndent);
|
|
9
|
+
maybe.indent(isIndentBefore(path));
|
|
10
|
+
print('<');
|
|
11
|
+
print('__name');
|
|
12
|
+
|
|
13
|
+
for (const attr of path.get('attributes')) {
|
|
14
|
+
maybe.print.space(!coupleLines);
|
|
15
|
+
print(attr);
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
if (isCoupleLines(path))
|
|
19
|
+
print.breakline();
|
|
20
|
+
|
|
21
|
+
if (path.node.selfClosing)
|
|
22
|
+
print('/');
|
|
23
|
+
|
|
24
|
+
print('>');
|
|
25
|
+
maybe.indent.dec(shouldIndent);
|
|
26
|
+
};
|
package/package.json
CHANGED
|
@@ -1,48 +0,0 @@
|
|
|
1
|
-
import {isCoupleLines} from '#is';
|
|
2
|
-
|
|
3
|
-
const isNotJSX = ({parentPath}) => {
|
|
4
|
-
const grandPath = parentPath.parentPath;
|
|
5
|
-
|
|
6
|
-
if (grandPath.isObjectProperty())
|
|
7
|
-
return false;
|
|
8
|
-
|
|
9
|
-
if (grandPath.isCallExpression())
|
|
10
|
-
return false;
|
|
11
|
-
|
|
12
|
-
if (grandPath.isJSXElement())
|
|
13
|
-
return false;
|
|
14
|
-
|
|
15
|
-
if (grandPath.isJSXExpressionContainer())
|
|
16
|
-
return false;
|
|
17
|
-
|
|
18
|
-
if (grandPath.isJSXFragment())
|
|
19
|
-
return false;
|
|
20
|
-
|
|
21
|
-
return !grandPath.isLogicalExpression();
|
|
22
|
-
};
|
|
23
|
-
|
|
24
|
-
export const JSXOpeningElement = (path, {print, maybe}) => {
|
|
25
|
-
maybe.indent(isNotJSX(path));
|
|
26
|
-
print('<');
|
|
27
|
-
print('__name');
|
|
28
|
-
|
|
29
|
-
const coupleLines = isCoupleLines(path);
|
|
30
|
-
const noCoupleLines = !coupleLines;
|
|
31
|
-
const shouldIndent = coupleLines && path.parentPath.parentPath.isJSXElement();
|
|
32
|
-
|
|
33
|
-
maybe.indent.inc(shouldIndent);
|
|
34
|
-
|
|
35
|
-
for (const attr of path.get('attributes')) {
|
|
36
|
-
maybe.print.space(noCoupleLines);
|
|
37
|
-
print(attr);
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
if (isCoupleLines(path))
|
|
41
|
-
print.breakline();
|
|
42
|
-
|
|
43
|
-
if (path.node.selfClosing)
|
|
44
|
-
print('/');
|
|
45
|
-
|
|
46
|
-
print('>');
|
|
47
|
-
maybe.indent.dec(shouldIndent);
|
|
48
|
-
};
|