Add feature-exists() builtin function
This commit is contained in:
parent
8eb9620a1a
commit
f82f1f3eee
26
src/builtin/macros.rs
Normal file
26
src/builtin/macros.rs
Normal 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));
|
||||
};
|
||||
}
|
@ -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),
|
||||
}
|
||||
});
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user