Skip to content

Commit f66c6d7

Browse files
committed
Bundled @layer should be inside @import conditions
1 parent dc8fb7f commit f66c6d7

File tree

1 file changed

+57
-9
lines changed

1 file changed

+57
-9
lines changed

src/bundler.rs

Lines changed: 57 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -632,8 +632,17 @@ impl<'a, 'o, 's, P: SourceProvider> Bundler<'a, 'o, 's, P> {
632632
}
633633
}
634634

635-
// Wrap rules in the appropriate @media and @supports rules.
635+
// Wrap rules in the appropriate @layer, @media, and @supports rules.
636636
let stylesheet = &mut stylesheets[source_index as usize];
637+
638+
if stylesheet.layer.is_some() {
639+
rules = vec![CssRule::LayerBlock(LayerBlockRule {
640+
name: stylesheet.layer.take().unwrap(),
641+
rules: CssRuleList(rules),
642+
loc: stylesheet.loc,
643+
})]
644+
}
645+
637646
if !stylesheet.media.media_queries.is_empty() {
638647
rules = vec![CssRule::Media(MediaRule {
639648
query: std::mem::replace(&mut stylesheet.media, MediaList::new()),
@@ -650,14 +659,6 @@ impl<'a, 'o, 's, P: SourceProvider> Bundler<'a, 'o, 's, P> {
650659
})]
651660
}
652661

653-
if stylesheet.layer.is_some() {
654-
rules = vec![CssRule::LayerBlock(LayerBlockRule {
655-
name: stylesheet.layer.take().unwrap(),
656-
rules: CssRuleList(rules),
657-
loc: stylesheet.loc,
658-
})]
659-
}
660-
661662
dest.extend(rules);
662663
}
663664
}
@@ -1385,6 +1386,53 @@ mod tests {
13851386
"#}
13861387
);
13871388

1389+
// Layer order depends on @import conditions.
1390+
let res = bundle(
1391+
TestProvider {
1392+
map: fs! {
1393+
"/a.css": r#"
1394+
@import "b.css" layer(bar) (min-width: 1000px);
1395+
1396+
@layer baz {
1397+
#box { background: purple }
1398+
}
1399+
1400+
@layer bar {
1401+
#box { background: yellow }
1402+
}
1403+
"#,
1404+
"/b.css": r#"
1405+
#box { background: green }
1406+
"#
1407+
},
1408+
},
1409+
"/a.css",
1410+
);
1411+
assert_eq!(
1412+
res,
1413+
indoc! { r#"
1414+
@media (min-width: 1000px) {
1415+
@layer bar {
1416+
#box {
1417+
background: green;
1418+
}
1419+
}
1420+
}
1421+
1422+
@layer baz {
1423+
#box {
1424+
background: purple;
1425+
}
1426+
}
1427+
1428+
@layer bar {
1429+
#box {
1430+
background: #ff0;
1431+
}
1432+
}
1433+
"#}
1434+
);
1435+
13881436
error_test(
13891437
TestProvider {
13901438
map: fs! {

0 commit comments

Comments
 (0)