From d07c1d3a060e6937a4eca700db3225e71df1cde0 Mon Sep 17 00:00:00 2001 From: Connor Skees Date: Wed, 28 Jul 2021 02:08:20 -0400 Subject: [PATCH] support `@at-root` inside media query inside style rule --- README.md | 2 +- src/output.rs | 8 +++++++- tests/at-root.rs | 20 ++++++++++++++++++++ 3 files changed, 28 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 8f9f7ce..7689094 100644 --- a/README.md +++ b/README.md @@ -29,7 +29,7 @@ That said, there are a number of known missing features and bugs. The notable fe ``` indented syntax @forward and more complex uses of @use -complex uses of @at-root +media queries with @at-root @media query merging media queries with @import / as a separator in color functions, e.g. rgba(255, 255, 255 / 0) diff --git a/src/output.rs b/src/output.rs index eec1e57..3fa99de 100644 --- a/src/output.rs +++ b/src/output.rs @@ -327,7 +327,13 @@ impl Css { }))] } Stmt::Return(..) => unreachable!("@return: {:?}", stmt), - Stmt::AtRoot { .. } => unreachable!("@at-root: {:?}", stmt), + Stmt::AtRoot { body } => body + .into_iter() + .map(|r| self.parse_stmt(r)) + .collect::>>>()? + .into_iter() + .flatten() + .collect(), Stmt::Keyframes(k) => vec![Toplevel::Keyframes(k)], Stmt::KeyframesRuleSet(k) => { let KeyframesRuleSet { body, selector } = *k; diff --git a/tests/at-root.rs b/tests/at-root.rs index ef3605b..d18d212 100644 --- a/tests/at-root.rs +++ b/tests/at-root.rs @@ -107,6 +107,26 @@ test!( }", "a {\n color: red;\n}\n\na {\n color: red;\n}\n" ); +test!( + at_root_inside_media, + "@media screen { + @at-root a { + color: red; + } + }", + "@media screen {\n a {\n color: red;\n }\n}\n" +); +test!( + at_root_inside_media_inside_style_rule, + "b { + @media screen { + @at-root a { + color: red; + } + } + }", + "@media screen {\n a {\n color: red;\n }\n}\n" +); error!( #[ignore = "we do not currently validate missing closing curly braces"] missing_closing_curly_brace,