Skip newlines when parsing selectors (#13280)
* replace "\n" with " " when parsing CSS * add test to ensure important whitespace is preserved
This commit is contained in:
parent
f3e78807af
commit
d2be632635
2 changed files with 32 additions and 0 deletions
|
|
@ -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', () => {
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue