diff --git a/src/builtin/macros.rs b/src/builtin/macros.rs new file mode 100644 index 0000000..90021d1 --- /dev/null +++ b/src/builtin/macros.rs @@ -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)); + }; +} \ No newline at end of file diff --git a/src/builtin/meta.rs b/src/builtin/meta.rs index a77743a..7a9eec9 100644 --- a/src/builtin/meta.rs +++ b/src/builtin/meta.rs @@ -14,4 +14,25 @@ pub(crate) fn register(f: &mut BTreeMap) { 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), + } + }); } \ No newline at end of file