Skip to content

Commit c470f66

Browse files
committed
feature: @putout/printer: JSXElement: indent
1 parent b0cf465 commit c470f66

2 files changed

Lines changed: 30 additions & 10 deletions

File tree

lib/tokenize/jsx/fixture/jsx-element-nested-with-attributes.js

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,25 @@ function App(props) {
77
/>
88
</section>
99
);
10+
}
11+
12+
function Login(props) {
13+
return (
14+
<form
15+
onSubmit={submit}
16+
className="block inline-block width"
17+
action="/login"
18+
method="post"
19+
>
20+
<input
21+
required
22+
autoCapitalize="off"
23+
autoCorrect="off"
24+
autoFocus
25+
id="username"
26+
name="username"
27+
tabIndex="1"
28+
/>
29+
</form>
30+
);
1031
}

lib/tokenize/jsx/indent.js

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,12 @@ import {createTypeChecker} from '#type-checker';
33

44
const {isFunction} = types;
55

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-
}
6+
export const isNeedIndent = createTypeChecker([
7+
['-', hasComplexAttribute],
8+
['+: parentPath -> JSXElement'],
9+
['-: parentPath.parentPath -> !CallExpression'],
10+
['+: parentPath -> ArrowFunctionExpression'],
11+
]);
1612

1713
const isComplexAttribute = createTypeChecker([
1814
['+: -> JSXSpreadAttribute'],
@@ -24,6 +20,9 @@ const isComplexAttribute = createTypeChecker([
2420
function hasComplexAttribute(path) {
2521
const attributes = path.get('openingElement.attributes');
2622

23+
if (attributes.length > 4)
24+
return true;
25+
2726
for (const attribute of attributes) {
2827
if (isComplexAttribute(attribute))
2928
return true;

0 commit comments

Comments
 (0)