mirror of
https://github.com/danog/dart-sass.git
synced 2024-11-30 04:39:03 +01:00
Add support for nested maps to has-key (#1075)
This commit is contained in:
parent
6b66241e95
commit
f5e3a5a669
@ -6,6 +6,12 @@
|
|||||||
|
|
||||||
[map-get]: https://sass-lang.com/documentation/modules/map#get
|
[map-get]: https://sass-lang.com/documentation/modules/map#get
|
||||||
|
|
||||||
|
* Add support for nested maps in `map.has-key`.
|
||||||
|
For example, `map.has-key((a: (b: (c: d))), a, b, c)` would return true.
|
||||||
|
See [the documentation][map-has-key] for more details.
|
||||||
|
|
||||||
|
[map-has-key]: https://sass-lang.com/documentation/modules/map#has-key
|
||||||
|
|
||||||
* Add a `map.deep-merge()` function. This works like `map.merge()`, except that
|
* Add a `map.deep-merge()` function. This works like `map.merge()`, except that
|
||||||
nested map values are *also* recursively merged. For example:
|
nested map values are *also* recursively merged. For example:
|
||||||
|
|
||||||
|
@ -81,10 +81,18 @@ final _values = _function(
|
|||||||
(arguments) => SassList(
|
(arguments) => SassList(
|
||||||
arguments[0].assertMap("map").contents.values, ListSeparator.comma));
|
arguments[0].assertMap("map").contents.values, ListSeparator.comma));
|
||||||
|
|
||||||
final _hasKey = _function("has-key", r"$map, $key", (arguments) {
|
final _hasKey = _function("has-key", r"$map, $key, $keys...", (arguments) {
|
||||||
var map = arguments[0].assertMap("map");
|
var map = arguments[0].assertMap("map");
|
||||||
var key = arguments[1];
|
var keys = [arguments[1], ...arguments[2].asList];
|
||||||
return SassBoolean(map.contents.containsKey(key));
|
for (var key in keys.take(keys.length - 1)) {
|
||||||
|
var value = map.contents[key];
|
||||||
|
if (value is SassMap) {
|
||||||
|
map = value;
|
||||||
|
} else {
|
||||||
|
return sassFalse;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return SassBoolean(map.contents.containsKey(keys.last));
|
||||||
});
|
});
|
||||||
|
|
||||||
/// Merges [map1] and [map2], with values in [map2] taking precedence.
|
/// Merges [map1] and [map2], with values in [map2] taking precedence.
|
||||||
|
Loading…
Reference in New Issue
Block a user