Skip to content

Commit ea6fd95

Browse files
fix: account for global block in is_empty (#14677)
Fixes #14675
1 parent b0374f8 commit ea6fd95

File tree

4 files changed

+31
-4
lines changed

4 files changed

+31
-4
lines changed

.changeset/olive-pillows-fetch.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'svelte': patch
3+
---
4+
5+
fix: account for global block in `is_empty`

packages/svelte/src/compiler/phases/3-transform/css/index.js

+9-4
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ const visitors = {
142142

143143
// keep empty rules in dev, because it's convenient to
144144
// see them in devtools
145-
if (!dev && is_empty(node)) {
145+
if (!dev && is_empty(node, is_in_global_block(path))) {
146146
if (state.minify) {
147147
state.code.remove(node.start, node.end);
148148
} else {
@@ -398,8 +398,11 @@ function remove_preceding_whitespace(end, state) {
398398
if (start < end) state.code.remove(start, end);
399399
}
400400

401-
/** @param {Css.Rule} rule */
402-
function is_empty(rule) {
401+
/**
402+
* @param {Css.Rule} rule
403+
* @param {boolean} is_in_global_block
404+
*/
405+
function is_empty(rule, is_in_global_block) {
403406
if (rule.metadata.is_global_block) {
404407
return rule.block.children.length === 0;
405408
}
@@ -410,7 +413,9 @@ function is_empty(rule) {
410413
}
411414

412415
if (child.type === 'Rule') {
413-
if (is_used(child) && !is_empty(child)) return false;
416+
if ((is_used(child) || is_in_global_block) && !is_empty(child, is_in_global_block)) {
417+
return false;
418+
}
414419
}
415420

416421
if (child.type === 'Atrule') {
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
2+
/* :global{*/
3+
:root{
4+
.use{
5+
color: red;
6+
}
7+
}
8+
/*}*/
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<style>
2+
:global{
3+
:root{
4+
.use{
5+
color: red;
6+
}
7+
}
8+
}
9+
</style>

0 commit comments

Comments
 (0)