From 5eeee2f01f2d71cae241f8a8cb76869ec6b964fd Mon Sep 17 00:00:00 2001 From: ConnorSkees <39542938+ConnorSkees@users.noreply.github.com> Date: Tue, 16 Jun 2020 22:00:45 -0400 Subject: [PATCH] resolve issue with @ at-root --- CHANGELOG.md | 3 +++ src/output.rs | 3 ++- src/parse/mod.rs | 1 + tests/at-root.rs | 5 +++++ 4 files changed, 11 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index ef4749e..0bdde4f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,6 @@ +# 0.9.1 + - fix issue in which `@at-root` would panic when placed after a ruleset + # 0.9.0 This release is focused on setting up the groundwork for implementing `@extend` as well diff --git a/src/output.rs b/src/output.rs index 6f97d31..35c541c 100644 --- a/src/output.rs +++ b/src/output.rs @@ -114,7 +114,8 @@ impl Css { Stmt::UnknownAtRule { params, name, body, .. } => vec![Toplevel::UnknownAtRule { params, name, body }], - Stmt::Return(..) | Stmt::AtRoot { .. } => unreachable!(), + Stmt::Return(..) => unreachable!("@return: {:?}", stmt), + Stmt::AtRoot { .. } => unreachable!("@at-root: {:?}", stmt), }) } diff --git a/src/parse/mod.rs b/src/parse/mod.rs index f68a85e..2251a93 100644 --- a/src/parse/mod.rs +++ b/src/parse/mod.rs @@ -283,6 +283,7 @@ impl<'a> Parser<'a> { let body = self.parse_stmt()?; self.scopes.pop(); self.super_selectors.pop(); + self.at_root = self.super_selectors.is_empty(); stmts.push(Stmt::RuleSet { selector, body, diff --git a/tests/at-root.rs b/tests/at-root.rs index e16d4e5..a64e0af 100644 --- a/tests/at-root.rs +++ b/tests/at-root.rs @@ -63,3 +63,8 @@ test!( "test {\n @at-root {\n #{&} {\n foo {\n bar: baz;\n }\n }\n }\n}\n", "test foo {\n bar: baz;\n}\n" ); +test!( + style_before_at_root, + "a {}\n\n@at-root {\n @-ms-viewport { width: device-width; }\n}\n", + "@-ms-viewport {\n width: device-width;\n}\n" +); \ No newline at end of file