Skip to content
Merged
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
10 changes: 10 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -348,7 +348,17 @@ function unwrapRootRule(rule) {
}
}

let parent = rule.parent
rule.remove()

if (escapes) {
// Remove at-rules which were left empty after escaping from them
while (parent instanceof AtRule && parent.nodes.length === 0) {
let next = parent.parent
parent.remove()
parent = next
}
}
}

const ROOT_RULE_MERGE_SEL = Symbol('rootRuleMergeSel')
Expand Down
53 changes: 53 additions & 0 deletions index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -439,6 +439,59 @@ test('at-root supports (without: foo) 5', () => {
)
})

test('at-root removes at-rules left empty after escaping', () => {
run(
`@media x {
a {
@at-root (without: media) {
b {}
}
}
}`,
`a b {}`
)
run(
`@media x {
a {
@at-root (without: media) {
b {}
}
c: d;
}
}`,
`a b {}
@media x {
a { c: d }
}`
)
run(
`@media x {
@supports (y:z) {
a {
@at-root (without: media) {
b {}
}
}
}
}`,
`@supports (y:z) {
a b {}
}`
)
run(
`@supports (y:z) {
@media x {
a {
@at-root (without: all) {
b {}
}
}
}
}`,
`b {}`
)
})

test('replaces ampersand', () => {
run('a { body &:hover b {} }', 'body a:hover b {}')
})
Expand Down
Loading