@@ -621,34 +621,37 @@ function transformJavaScript(ast: import('@babel/types').Node, { env }: Transfor
621
621
622
622
function sortInside ( ast : import ( '@babel/types' ) . Node ) {
623
623
visit ( ast , ( node , path ) => {
624
- let concat = path . find ( ( entry ) => {
625
- return entry . parent && entry . parent . type === 'BinaryExpression' && entry . parent . operator === '+'
626
- } )
624
+ let start = true
625
+ let end = true
626
+
627
+ for ( let entry of path ) {
628
+ if ( ! entry . parent ) continue
629
+
630
+ // Nodes inside concat expressions shouldn't collapse whitespace
631
+ // depending on which side they're part of.
632
+ if ( entry . parent . type === 'BinaryExpression' && entry . parent . operator === '+' ) {
633
+ start = entry . key !== 'right'
634
+ end = entry . key !== 'left'
635
+
636
+ break
637
+ }
638
+ }
627
639
628
640
if ( isStringLiteral ( node ) ) {
629
641
sortStringLiteral ( node , {
630
642
env,
631
- collapseWhitespace : {
632
- start : concat ?. key !== 'right' ,
633
- end : concat ?. key !== 'left' ,
634
- } ,
643
+ collapseWhitespace : { start, end } ,
635
644
} )
636
645
} else if ( node . type === 'TemplateLiteral' ) {
637
646
sortTemplateLiteral ( node , {
638
647
env,
639
- collapseWhitespace : {
640
- start : concat ?. key !== 'right' ,
641
- end : concat ?. key !== 'left' ,
642
- } ,
648
+ collapseWhitespace : { start, end } ,
643
649
} )
644
650
} else if ( node . type === 'TaggedTemplateExpression' ) {
645
651
if ( isSortableTemplateExpression ( node , functions ) ) {
646
652
sortTemplateLiteral ( node . quasi , {
647
653
env,
648
- collapseWhitespace : {
649
- start : concat ?. key !== 'right' ,
650
- end : concat ?. key !== 'left' ,
651
- } ,
654
+ collapseWhitespace : { start, end } ,
652
655
} )
653
656
}
654
657
}
0 commit comments