Skip to content

Commit 4b553d7

Browse files
committed
Bail out of whitespace removal inside nested concat expressions
1 parent 0eb4461 commit 4b553d7

File tree

2 files changed

+10
-4
lines changed

2 files changed

+10
-4
lines changed

src/index.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -630,10 +630,8 @@ function transformJavaScript(ast: import('@babel/types').Node, { env }: Transfor
630630
// Nodes inside concat expressions shouldn't collapse whitespace
631631
// depending on which side they're part of.
632632
if (entry.parent.type === 'BinaryExpression' && entry.parent.operator === '+') {
633-
start = entry.key !== 'right'
634-
end = entry.key !== 'left'
635-
636-
break
633+
start &&= entry.key !== 'right'
634+
end &&= entry.key !== 'left'
637635
}
638636
}
639637

tests/format.test.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,14 @@ describe('whitespace', () => {
5858
expect(result).toEqual(';<div className={`text-red-500 underline ${foo}-bar flex`}></div>')
5959
})
6060

61+
test('whitespace is not trimmed inside concat expressions', async ({ expect }) => {
62+
let result = await format(";<div className={a + ' p-4 ' + b}></div>", {
63+
parser: 'babel',
64+
})
65+
66+
expect(result).toEqual(";<div className={a + ' p-4 ' + b}></div>")
67+
})
68+
6169
test('duplicate classes are dropped', async ({ expect }) => {
6270
let result = await format('<div class="underline line-through underline flex"></div>')
6371

0 commit comments

Comments
 (0)