diff --git a/packages/tailwindcss/src/css-parser.test.ts b/packages/tailwindcss/src/css-parser.test.ts index c2a724114cd9..f3146d04a15e 100644 --- a/packages/tailwindcss/src/css-parser.test.ts +++ b/packages/tailwindcss/src/css-parser.test.ts @@ -600,6 +600,28 @@ describe.each(['Unix', 'Windows'])('Line endings: %s', (lineEndings) => { }, ]) }) + + it('should parse a multi-line selector', () => { + expect(parse(['.foo,', '.bar,', '.baz', '{', 'color:red;', '}'].join('\n'))).toEqual([ + { + kind: 'rule', + selector: '.foo, .bar, .baz', + nodes: [{ kind: 'declaration', property: 'color', value: 'red', important: false }], + }, + ]) + }) + + it('should parse a multi-line selector and preserves important whitespace', () => { + expect( + parse(['.foo,', '.bar,', '.baz\t\n \n .qux', '{', 'color:red;', '}'].join('\n')), + ).toEqual([ + { + kind: 'rule', + selector: '.foo, .bar, .baz .qux', + nodes: [{ kind: 'declaration', property: 'color', value: 'red', important: false }], + }, + ]) + }) }) describe('at-rules', () => { diff --git a/packages/tailwindcss/src/css-parser.ts b/packages/tailwindcss/src/css-parser.ts index 59fcd9dcfd05..99794c4f60e7 100644 --- a/packages/tailwindcss/src/css-parser.ts +++ b/packages/tailwindcss/src/css-parser.ts @@ -142,6 +142,16 @@ export function parse(input: string) { continue } + // Replace new lines with spaces. + else if (char === '\n') { + if (current.length === 0) continue + + let last = current[current.length - 1] + if (last !== ' ' && last !== '\n' && last !== '\t') { + current += ' ' + } + } + // Start of a custom property. // // Custom properties are very permissive and can contain almost any