From 096abb6ca030ff6f2dab4f65a5fcc24114fccf97 Mon Sep 17 00:00:00 2001 From: ConnorSkees <39542938+ConnorSkees@users.noreply.github.com> Date: Sun, 24 May 2020 09:07:16 -0400 Subject: [PATCH] handle selector with nothing after colon --- src/selector/mod.rs | 7 +++++-- tests/selectors.rs | 8 ++++++-- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/src/selector/mod.rs b/src/selector/mod.rs index 9417824..bac46f3 100644 --- a/src/selector/mod.rs +++ b/src/selector/mod.rs @@ -1,5 +1,7 @@ use std::fmt::{self, Display, Write}; +use codemap::Span; + use peekmore::{PeekMore, PeekMoreIterator}; use crate::common::{Brackets, ListSeparator, QuoteKind}; @@ -360,7 +362,7 @@ impl Selector { } ':' => { iter.next(); - let sel = Self::consume_pseudo_selector(&mut iter, scope, super_selector)?; + let sel = Self::consume_pseudo_selector(&mut iter, scope, super_selector, pos)?; match &sel { SelectorKind::PseudoParen(_, s) => { if s.contains_super_selector() { @@ -399,8 +401,9 @@ impl Selector { toks: &mut PeekMoreIterator, scope: &Scope, super_selector: &Selector, + span_before: Span, ) -> SassResult { - let is_pseudo_element = if toks.peek().unwrap().kind == ':' { + let is_pseudo_element = if toks.peek().ok_or(("Expected identifier.", span_before))?.kind == ':' { toks.next(); true } else { diff --git a/tests/selectors.rs b/tests/selectors.rs index 31efb7f..bc0f20a 100644 --- a/tests/selectors.rs +++ b/tests/selectors.rs @@ -544,8 +544,12 @@ test!( error!(nothing_after_period, ". {}", "Error: Expected identifier."); error!(nothing_after_hash, "# {}", "Error: Expected identifier."); error!(nothing_after_percent, "% {}", "Error: Expected identifier."); -error!(nothing_after_colon, ": {}", "Error: Expected identifier."); +error!(no_ident_after_colon, ": {}", "Error: Expected identifier."); error!( - non_ident_after_colon, + non_ident_char_after_colon, ":#ab {}", "Error: Expected identifier." ); +error!( + nothing_after_colon, + "a:{}", "Error: Expected identifier." +);