implement simple-selectors

This commit is contained in:
ConnorSkees 2020-06-07 17:40:24 -04:00
parent e76903cb47
commit 113e011652
2 changed files with 46 additions and 1 deletions

View File

@ -3,6 +3,7 @@
use super::{Builtin, GlobalFunctionMap};
use crate::args::CallArgs;
use crate::common::{Brackets, ListSeparator, QuoteKind};
use crate::error::SassResult;
use crate::scope::Scope;
use crate::selector::{
@ -42,7 +43,36 @@ fn simple_selectors(
super_selector: &Selector,
) -> SassResult<Value> {
args.max_args(1)?;
todo!("built-in fn simple-selectors")
// todo: Value::to_compound_selector
let selector = arg!(args, scope, super_selector, 0, "selector").to_selector(
args.span(),
scope,
super_selector,
"selector",
false,
)?;
if selector.0.components.len() != 1 {
return Err(("$selector: expected selector.", args.span()).into());
}
let compound = if let Some(ComplexSelectorComponent::Compound(compound)) =
selector.0.components[0].components.get(0).cloned()
{
compound
} else {
todo!()
};
Ok(Value::List(
compound
.components
.into_iter()
.map(|simple| Value::String(simple.to_string(), QuoteKind::None))
.collect(),
ListSeparator::Comma,
Brackets::None,
))
}
fn selector_parse(

15
tests/simple-selectors.rs Normal file
View File

@ -0,0 +1,15 @@
#![cfg(test)]
#[macro_use]
mod macros;
test!(
two_classes,
"a {\n color: simple-selectors(\".foo.bar\");\n}\n",
"a {\n color: .foo, .bar;\n}\n"
);
test!(
three_classes,
"a {\n color: simple-selectors(\".foo.bar.baz\");\n}\n",
"a {\n color: .foo, .bar, .baz;\n}\n"
);