alias sass:selector builtin functions

This commit is contained in:
Connor Skees 2020-07-26 00:15:34 -04:00
parent 15f657df6d
commit d6126110e9
3 changed files with 28 additions and 11 deletions

View File

@ -9,7 +9,7 @@ use crate::{
value::Value,
};
fn is_superselector(mut args: CallArgs, parser: &mut Parser<'_>) -> SassResult<Value> {
pub(crate) fn is_superselector(mut args: CallArgs, parser: &mut Parser<'_>) -> SassResult<Value> {
args.max_args(2)?;
let parent_selector = args
.get_err(0, "super")?
@ -21,7 +21,7 @@ fn is_superselector(mut args: CallArgs, parser: &mut Parser<'_>) -> SassResult<V
))
}
fn simple_selectors(mut args: CallArgs, parser: &mut Parser<'_>) -> SassResult<Value> {
pub(crate) fn simple_selectors(mut args: CallArgs, parser: &mut Parser<'_>) -> SassResult<Value> {
args.max_args(1)?;
// todo: Value::to_compound_selector
let selector = args
@ -51,7 +51,7 @@ fn simple_selectors(mut args: CallArgs, parser: &mut Parser<'_>) -> SassResult<V
))
}
fn selector_parse(mut args: CallArgs, parser: &mut Parser<'_>) -> SassResult<Value> {
pub(crate) fn selector_parse(mut args: CallArgs, parser: &mut Parser<'_>) -> SassResult<Value> {
args.max_args(1)?;
Ok(args
.get_err(0, "selector")?
@ -59,7 +59,7 @@ fn selector_parse(mut args: CallArgs, parser: &mut Parser<'_>) -> SassResult<Val
.into_value())
}
fn selector_nest(args: CallArgs, parser: &mut Parser<'_>) -> SassResult<Value> {
pub(crate) fn selector_nest(args: CallArgs, parser: &mut Parser<'_>) -> SassResult<Value> {
let span = args.span();
let selectors = args.get_variadic()?;
if selectors.is_empty() {
@ -80,7 +80,7 @@ fn selector_nest(args: CallArgs, parser: &mut Parser<'_>) -> SassResult<Value> {
.into_value())
}
fn selector_append(args: CallArgs, parser: &mut Parser<'_>) -> SassResult<Value> {
pub(crate) fn selector_append(args: CallArgs, parser: &mut Parser<'_>) -> SassResult<Value> {
let span = args.span();
let selectors = args.get_variadic()?;
if selectors.is_empty() {
@ -138,7 +138,7 @@ fn selector_append(args: CallArgs, parser: &mut Parser<'_>) -> SassResult<Value>
.into_value())
}
fn selector_extend(mut args: CallArgs, parser: &mut Parser<'_>) -> SassResult<Value> {
pub(crate) fn selector_extend(mut args: CallArgs, parser: &mut Parser<'_>) -> SassResult<Value> {
args.max_args(3)?;
let selector = args
.get_err(0, "selector")?
@ -153,7 +153,7 @@ fn selector_extend(mut args: CallArgs, parser: &mut Parser<'_>) -> SassResult<Va
Ok(Extender::extend(selector.0, source.0, target.0, args.span())?.to_sass_list())
}
fn selector_replace(mut args: CallArgs, parser: &mut Parser<'_>) -> SassResult<Value> {
pub(crate) fn selector_replace(mut args: CallArgs, parser: &mut Parser<'_>) -> SassResult<Value> {
args.max_args(3)?;
let selector = args
.get_err(0, "selector")?
@ -167,7 +167,7 @@ fn selector_replace(mut args: CallArgs, parser: &mut Parser<'_>) -> SassResult<V
Ok(Extender::replace(selector.0, source.0, target.0, args.span())?.to_sass_list())
}
fn selector_unify(mut args: CallArgs, parser: &mut Parser<'_>) -> SassResult<Value> {
pub(crate) fn selector_unify(mut args: CallArgs, parser: &mut Parser<'_>) -> SassResult<Value> {
args.max_args(2)?;
let selector1 = args
.get_err(0, "selector1")?

View File

@ -1,4 +1,4 @@
mod functions;
pub(crate) mod modules;
pub(crate) use functions::{math, meta, Builtin, GLOBAL_FUNCTIONS};
pub(crate) use functions::{math, meta, selector, Builtin, GLOBAL_FUNCTIONS};

View File

@ -1,5 +1,22 @@
use crate::{
args::CallArgs, builtin::modules::Module, error::SassResult, parse::Parser, value::Value,
args::CallArgs,
builtin::modules::Module,
builtin::selector::{
is_superselector, selector_append, selector_extend, selector_nest, selector_parse,
selector_replace, selector_unify, simple_selectors,
},
error::SassResult,
parse::Parser,
value::Value,
};
pub(crate) fn declare(_f: &mut Module) {}
pub(crate) fn declare(f: &mut Module) {
f.insert_builtin("is-superselector", is_superselector);
f.insert_builtin("append", selector_append);
f.insert_builtin("extend", selector_extend);
f.insert_builtin("nest", selector_nest);
f.insert_builtin("parse", selector_parse);
f.insert_builtin("replace", selector_replace);
f.insert_builtin("unify", selector_unify);
f.insert_builtin("simple-selectors", simple_selectors);
}