diff --git a/src/builtin/map.rs b/src/builtin/map.rs index 474b73a..4699fa8 100644 --- a/src/builtin/map.rs +++ b/src/builtin/map.rs @@ -81,4 +81,19 @@ pub(crate) fn register(f: &mut HashMap) { Ok(Value::Map(map1)) }), ); + f.insert( + "map-remove".to_owned(), + Box::new(|mut args, _| { + let mut map = match arg!(args, 0, "map") { + Value::Map(m) => m, + Value::List(v, ..) if v.is_empty() => SassMap::new(), + v => return Err(format!("$map: {} is not a map.", v).into()), + }; + let keys = args.get_variadic()?; + for key in keys { + map.remove(&key); + } + Ok(Value::Map(map)) + }), + ); } diff --git a/tests/map.rs b/tests/map.rs index eb00134..4e6efa3 100644 --- a/tests/map.rs +++ b/tests/map.rs @@ -119,3 +119,13 @@ error!( map_has_key_one_arg, "a {\n color: map-has-key(1);\n}\n", "Error: Missing argument $key." ); +test!( + map_remove_one, + "a {\n color: inspect(map-remove((\"foo\": 1, \"bar\": 2), \"bar\"));\n}\n", + "a {\n color: (\"foo\": 1);\n}\n" +); +test!( + map_remove_two, + "a {\n color: inspect(map-remove((\"foo\": 1, \"bar\": 2, \"baz\": 3), \"bar\", \"baz\"));\n}\n", + "a {\n color: (\"foo\": 1);\n}\n" +);