Skip to content

Commit 9753645

Browse files
authored
Merge pull request #109 from ony3000/dogfooding
Fix line wrapping in JSX mapped from object references that include optional chaining
2 parents 76c15e8 + 0ece5e1 commit 9753645

5 files changed

Lines changed: 150 additions & 6 deletions

File tree

src/core-parts/finder.ts

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -158,20 +158,22 @@ export function findTargetClassNameNodes(ast: AST, options: ResolvedOptions): Cl
158158
recursiveProps = ['left', 'right'];
159159
break;
160160
}
161-
case 'CallExpression': {
161+
case 'CallExpression':
162+
case 'OptionalCallExpression': {
162163
recursiveProps = ['arguments'];
163164
break;
164165
}
165-
case 'ConditionalExpression':
166-
case 'IfStatement': {
167-
recursiveProps = ['consequent', 'alternate'];
168-
break;
169-
}
166+
case 'ChainExpression':
170167
case 'ExpressionStatement':
171168
case 'JSXExpressionContainer': {
172169
recursiveProps = ['expression'];
173170
break;
174171
}
172+
case 'ConditionalExpression':
173+
case 'IfStatement': {
174+
recursiveProps = ['consequent', 'alternate'];
175+
break;
176+
}
175177
case 'ExportDefaultDeclaration':
176178
case 'ExportNamedDeclaration': {
177179
recursiveProps = ['declaration'];

tests/babel/others/absolute.test.ts

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -324,6 +324,42 @@ function Foo() {
324324
}
325325
return elem;
326326
}
327+
`,
328+
options: {
329+
printWidth: 80,
330+
},
331+
},
332+
{
333+
name: 'JSX mapped from object references including optional chaining',
334+
input: `
335+
function Foo() {
336+
return (
337+
<div>
338+
{foo?.data.map((_, index) => (
339+
<div key={index} className="lorem ipsum dolor sit amet consectetur adipiscing elit proin ex massa hendrerit eu posuere eu volutpat id neque pellentesque">
340+
content
341+
</div>
342+
))}
343+
</div>
344+
);
345+
}
346+
`,
347+
output: `function Foo() {
348+
return (
349+
<div>
350+
{foo?.data.map((_, index) => (
351+
<div
352+
key={index}
353+
className="lorem ipsum dolor sit amet consectetur adipiscing elit
354+
proin ex massa hendrerit eu posuere eu volutpat id neque
355+
pellentesque"
356+
>
357+
content
358+
</div>
359+
))}
360+
</div>
361+
);
362+
}
327363
`,
328364
options: {
329365
printWidth: 80,

tests/babel/others/relative.test.ts

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -319,6 +319,41 @@ function Foo() {
319319
}
320320
return elem;
321321
}
322+
`,
323+
options: {
324+
printWidth: 80,
325+
},
326+
},
327+
{
328+
name: 'JSX mapped from object references including optional chaining',
329+
input: `
330+
function Foo() {
331+
return (
332+
<div>
333+
{foo?.data.map((_, index) => (
334+
<div key={index} className="lorem ipsum dolor sit amet consectetur adipiscing elit proin ex massa hendrerit eu posuere eu volutpat id neque pellentesque">
335+
content
336+
</div>
337+
))}
338+
</div>
339+
);
340+
}
341+
`,
342+
output: `function Foo() {
343+
return (
344+
<div>
345+
{foo?.data.map((_, index) => (
346+
<div
347+
key={index}
348+
className="lorem ipsum dolor sit amet consectetur adipiscing elit proin ex massa hendrerit
349+
eu posuere eu volutpat id neque pellentesque"
350+
>
351+
content
352+
</div>
353+
))}
354+
</div>
355+
);
356+
}
322357
`,
323358
options: {
324359
printWidth: 80,

tests/typescript/others/absolute.test.ts

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -324,6 +324,42 @@ function Foo() {
324324
}
325325
return elem;
326326
}
327+
`,
328+
options: {
329+
printWidth: 80,
330+
},
331+
},
332+
{
333+
name: 'JSX mapped from object references including optional chaining',
334+
input: `
335+
function Foo() {
336+
return (
337+
<div>
338+
{foo?.data.map((_, index) => (
339+
<div key={index} className="lorem ipsum dolor sit amet consectetur adipiscing elit proin ex massa hendrerit eu posuere eu volutpat id neque pellentesque">
340+
content
341+
</div>
342+
))}
343+
</div>
344+
);
345+
}
346+
`,
347+
output: `function Foo() {
348+
return (
349+
<div>
350+
{foo?.data.map((_, index) => (
351+
<div
352+
key={index}
353+
className="lorem ipsum dolor sit amet consectetur adipiscing elit
354+
proin ex massa hendrerit eu posuere eu volutpat id neque
355+
pellentesque"
356+
>
357+
content
358+
</div>
359+
))}
360+
</div>
361+
);
362+
}
327363
`,
328364
options: {
329365
printWidth: 80,

tests/typescript/others/relative.test.ts

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -319,6 +319,41 @@ function Foo() {
319319
}
320320
return elem;
321321
}
322+
`,
323+
options: {
324+
printWidth: 80,
325+
},
326+
},
327+
{
328+
name: 'JSX mapped from object references including optional chaining',
329+
input: `
330+
function Foo() {
331+
return (
332+
<div>
333+
{foo?.data.map((_, index) => (
334+
<div key={index} className="lorem ipsum dolor sit amet consectetur adipiscing elit proin ex massa hendrerit eu posuere eu volutpat id neque pellentesque">
335+
content
336+
</div>
337+
))}
338+
</div>
339+
);
340+
}
341+
`,
342+
output: `function Foo() {
343+
return (
344+
<div>
345+
{foo?.data.map((_, index) => (
346+
<div
347+
key={index}
348+
className="lorem ipsum dolor sit amet consectetur adipiscing elit proin ex massa hendrerit
349+
eu posuere eu volutpat id neque pellentesque"
350+
>
351+
content
352+
</div>
353+
))}
354+
</div>
355+
);
356+
}
322357
`,
323358
options: {
324359
printWidth: 80,

0 commit comments

Comments
 (0)