Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 14 additions & 5 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -178,11 +178,17 @@ function breakOut(child, currentNode) {
function createFnAtruleChilds(bubble) {
return function atruleChilds(rule, atrule, bubbling, mergeSels = bubbling) {
let children = []
let groups = []
atrule.each(child => {
if (child.type === 'rule' && bubbling) {
if (mergeSels) {
child.selectors = mergeSelectors(rule, child)
}
// Declarations after a nested rule stay after it, like outside at-rules
if (children.length) {
groups.push(children)
children = []
}
} else if (child.type === 'atrule' && child.nodes) {
if (bubble[child.name]) {
atruleChilds(rule, child, mergeSels)
Expand All @@ -193,12 +199,15 @@ function createFnAtruleChilds(bubble) {
children.push(child)
}
})
if (bubbling && children.length) {
let clone = rule.clone({ nodes: [] })
for (let child of children) {
clone.append(child)
if (children.length) groups.push(children)
if (bubbling) {
for (let group of groups) {
let clone = rule.clone({ nodes: [] })
group[0].before(clone)
for (let child of group) {
clone.append(child)
}
}
atrule.prepend(clone)
}
}
}
Expand Down
11 changes: 11 additions & 0 deletions index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -709,6 +709,17 @@ test('copies rule for declarations after nested rule and before at-rule', () =>
)
})

test('copies rule for declarations after nested rule inside at-rule', () => {
run(
'a { @media screen { a: 1; &b { b: 2 } c: 1; &c { d: 5 } e: 6 } }',
'@media screen { a { a: 1 } ab { b: 2 } a { c: 1 } ac { d: 5 } a { e: 6 } }'
)
run(
'a { @supports (a: 1) { &b { b: 2 } c: 1 } }',
'@supports (a: 1) { ab { b: 2 } a { c: 1 } }'
)
})

test('does not replace ampersand inside string', () => {
run(
'div { &[data-category="sound & vision"] {} }',
Expand Down
Loading