split @apply values by spaces, tabs and newlines

Fixes: #2222
This commit is contained in:
Robin Malfait 2020-08-22 00:03:42 +02:00
parent c16bf207bc
commit 3bf6348523
No known key found for this signature in database
GPG key ID: 92F53D68B9041AFE
2 changed files with 48 additions and 1 deletions

View file

@ -47,6 +47,53 @@ test('it copies class declarations into itself', () => {
})
})
test('apply values can contain tabs', () => {
const input = `
.a {
@apply p-4\tm-4;
}
`
const expected = `
.a {
margin: 1rem;
padding: 1rem;
}
`
expect.assertions(2)
return run(input).then(result => {
expect(result.css).toMatchCss(expected)
expect(result.warnings().length).toBe(0)
})
})
test('apply values can contain newlines', () => {
const input = `
.a {
@apply p-4 m-4
flex flex-col;
}
`
const expected = `
.a {
display: flex;
flex-direction: column;
margin: 1rem;
padding: 1rem;
}
`
expect.assertions(2)
return run(input).then(result => {
expect(result.css).toMatchCss(expected)
expect(result.warnings().length).toBe(0)
})
})
test('selectors with invalid characters do not need to be manually escaped', () => {
const input = `
.a\\:1\\/2 { color: red; }

View file

@ -200,7 +200,7 @@ function processApplyAtRules(css, lookupTree, config) {
importantEntries,
applyUtilityNames,
important = importantEntries.length > 0,
] = _.partition(applyRule.params.split(' '), n => n === '!important')
] = _.partition(applyRule.params.split(/[\s\t\n]+/g), n => n === '!important')
const currentUtilityNames = extractUtilityNames(rule.selector)