From 4263fd25320ebdb34f6c89e27a4f07dec12527e8 Mon Sep 17 00:00:00 2001 From: ConnorSkees <39542938+ConnorSkees@users.noreply.github.com> Date: Sun, 2 Feb 2020 18:01:09 -0500 Subject: [PATCH] Devour whitespace after `{` --- src/mixin.rs | 2 ++ src/selector.rs | 10 +++------- tests/mixins.rs | 5 +++++ 3 files changed, 10 insertions(+), 7 deletions(-) diff --git a/src/mixin.rs b/src/mixin.rs index 0b351a6..76e099a 100644 --- a/src/mixin.rs +++ b/src/mixin.rs @@ -50,6 +50,8 @@ impl Mixin { _ => return Err((pos, String::from("expected `(` or `{`"))), }; + devour_whitespace(toks); + let mut nesting = 1; let mut body = Vec::new(); diff --git a/src/selector.rs b/src/selector.rs index 2800e2c..dda67ab 100644 --- a/src/selector.rs +++ b/src/selector.rs @@ -127,12 +127,7 @@ impl Display for SelectorKind { SelectorKind::Attribute(attr) => write!(f, "{}", attr), SelectorKind::Pseudo(s) => write!(f, ":{}", s), SelectorKind::PseudoElement(s) => write!(f, "::{}", s), - SelectorKind::PseudoParen(s, val) => write!( - f, - ":{}({})", - s, - val - ), + SelectorKind::PseudoParen(s, val) => write!(f, ":{}({})", s, val), SelectorKind::Super | SelectorKind::None | SelectorKind::InterpolatedSuper => { write!(f, "") } @@ -239,7 +234,8 @@ impl<'a> SelectorParser<'a> { toks.push(' '); } } - self.selectors.push(SelectorKind::PseudoParen(s, toks.trim_end().to_owned())) + self.selectors + .push(SelectorKind::PseudoParen(s, toks.trim_end().to_owned())) } else { self.selectors.push(SelectorKind::Pseudo(s)) } diff --git a/tests/mixins.rs b/tests/mixins.rs index 47936fc..40a6ee5 100644 --- a/tests/mixins.rs +++ b/tests/mixins.rs @@ -9,6 +9,11 @@ test!( "b {\n color: red;\n}\n" ); test!(empty_mixin, "@mixin a {}\n\nb {\n @include a;\n}\n", ""); +test!( + just_a_comment, + "@mixin foo() {\n /* begin foo */\n}\n\na {\n @include foo();\n}\n", + "a {\n /* begin foo */\n}\n" +); test!( mixin_two_styles, "@mixin a {\n color: red;\n color: blue;\n}\n\nb {\n @include a;\n}\n",