Skip to content

Commit ec404c0

Browse files
committed
replace "\n" with " " when parsing CSS
1 parent f3e7880 commit ec404c0

File tree

2 files changed

+20
-0
lines changed

2 files changed

+20
-0
lines changed

packages/tailwindcss/src/css-parser.test.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -600,6 +600,16 @@ describe.each(['Unix', 'Windows'])('Line endings: %s', (lineEndings) => {
600600
},
601601
])
602602
})
603+
604+
it('should parse a multi-line selector', () => {
605+
expect(parse(['.foo,', '.bar,', '.baz', '{', 'color:red;', '}'].join('\n'))).toEqual([
606+
{
607+
kind: 'rule',
608+
selector: '.foo, .bar, .baz',
609+
nodes: [{ kind: 'declaration', property: 'color', value: 'red', important: false }],
610+
},
611+
])
612+
})
603613
})
604614

605615
describe('at-rules', () => {

packages/tailwindcss/src/css-parser.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,16 @@ export function parse(input: string) {
142142
continue
143143
}
144144

145+
// Replace new lines with spaces.
146+
else if (char === '\n') {
147+
if (current.length === 0) continue
148+
149+
let last = current[current.length - 1]
150+
if (last !== ' ' && last !== '\n' && last !== '\t') {
151+
current += ' '
152+
}
153+
}
154+
145155
// Start of a custom property.
146156
//
147157
// Custom properties are very permissive and can contain almost any

0 commit comments

Comments
 (0)