Add feature-exists() builtin function

This commit is contained in:
ConnorSkees 2020-02-03 07:22:20 -05:00
parent 8eb9620a1a
commit f82f1f3eee
2 changed files with 47 additions and 0 deletions

26
src/builtin/macros.rs Normal file
View File

@ -0,0 +1,26 @@
macro_rules! arg {
($args:ident, $idx:literal, $name:literal) => {
match $args.get(stringify!($idx)) {
Some(v) => v,
None => match $args.get($name) {
Some(v) => v,
None => panic!("missing variable"),
},
};
};
($args:ident, $idx:literal, $name:literal=$default:literal) => {
match $args.get(stringify!($idx)) {
Some(v) => v,
None => match $args.get($name) {
Some(v) => v,
None => $default,
},
};
};
}
macro_rules! decl {
($f:ident $name:literal, $body:expr) => {
$f.insert($name.to_owned(), Box::new($body));
};
}

View File

@ -14,4 +14,25 @@ pub(crate) fn register(f: &mut BTreeMap<String, Builtin>) {
Some(if_false)
}
});
decl!(f "feature-exists", |args| {
let feature: &Value = arg!(args, 0, "feature");
match feature.to_string().as_str() {
// A local variable will shadow a global variable unless
// `!global` is used.
"global-variable-shadowing" => Some(Value::False),
// the @extend rule will affect selectors nested in pseudo-classes
// like :not()
"extend-selector-pseudoclass" => Some(Value::False),
// Full support for unit arithmetic using units defined in the
// [Values and Units Level 3][] spec.
"units-level-3" => Some(Value::False),
// The Sass `@error` directive is supported.
"at-error" => Some(Value::True),
// The "Custom Properties Level 1" spec is supported. This means
// that custom properties are parsed statically, with only
// interpolation treated as SassScript.
"custom-property" => Some(Value::False),
_ => Some(Value::False),
}
});
}