From c4439c14fd847a7d32dbc41ee941c85e671eb538 Mon Sep 17 00:00:00 2001 From: Connor Skees Date: Sat, 4 Jul 2020 21:02:49 -0400 Subject: [PATCH] do not strip newlines after comments in selectors --- src/parse/mod.rs | 5 +++-- tests/selectors.rs | 5 +++++ 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/src/parse/mod.rs b/src/parse/mod.rs index 7efc1c7..32cfb8f 100644 --- a/src/parse/mod.rs +++ b/src/parse/mod.rs @@ -219,6 +219,7 @@ impl<'a> Parser<'a> { '/' => { self.toks.next(); let comment = self.parse_comment()?; + self.whitespace(); match comment.node { Comment::Silent => continue, Comment::Loud(s) => stmts.push(Stmt::Comment(s)), @@ -346,7 +347,6 @@ impl<'a> Parser<'a> { return Err(("Expected selector.", tok.pos()).into()); } self.parse_comment()?; - self.whitespace(); string.push(' '); } '{' => { @@ -403,11 +403,12 @@ impl<'a> Parser<'a> { Ok(Spanned { node: match self.toks.next() { Some(Token { kind: '/', .. }) => { - while let Some(tok) = self.toks.next() { + while let Some(tok) = self.toks.peek() { if tok.kind == '\n' { break; } span = span.merge(tok.pos); + self.toks.next(); } Comment::Silent diff --git a/tests/selectors.rs b/tests/selectors.rs index 5e6c21b..74fc127 100644 --- a/tests/selectors.rs +++ b/tests/selectors.rs @@ -663,6 +663,11 @@ test!( "@mixin foo {\n #{if(&, 'true', 'false')} {\n color: red;\n }\n}\n\n@include foo;\n\na {\n @include foo;\n}\n", "false {\n color: red;\n}\n\na true {\n color: red;\n}\n" ); +test!( + newline_is_preserved_when_following_comment, + "a, // 1\nb,\nc {\n color: red;\n}\n", + "a,\nb,\nc {\n color: red;\n}\n" +); error!( a_n_plus_b_n_invalid_odd, ":nth-child(ofdd) {\n color: &;\n}\n", "Error: Expected \"odd\"."