map.set($map, $key, $value) returns a new map with $key set to $value (add or replace). With extra keys—map.set($map, $keys..., $key, $value)—it walks a nested path and sets the final key. Load it with @use "sass:map" on Dart Sass 1.27+ for nested paths (module API overall needs 1.23+). There is no global map-set().
Use one key for top-level writes; pass a path for nested tokens:
Goal
Use
Add / update one top-level key
map.set($map, $key, $value)
Update a nested leaf
map.set($map, $k1, $k2, $leaf, $value)
Create a nested path from scratch
Same nested form — missing keys become empty maps
Overlay many keys
map.merge / map.deep-merge
Delete a key
map.remove / map.deep-remove
Global map-set()
Not provided — module only
Argument shape.
Official docs describe nested calls as $map, $keys..., $key, $value. In practice you pass one argument list: path keys, then the final key, then the value.
Nested paths write deep tokens without rebuilding the whole tree.
Use merge for bulk overlays; set for single writes.
Module only — no global map-set().
One line: when one map key must change, call map.set($map, $key, $value) or map.set($map, $path..., $value).
Practice
Compile Notes
Practical checklist:
checklist.txt
1. @use "sass:map"
2. Use map.set for single key / nested leaf writes
3. Use merge / deep-merge for many keys
4. Reassign: $map: map.set($map, ...)
5. Confirm with map.get / map.has-key
Frequently Asked Questions
map.set($map, $key, $value) returns a new map with $key set to $value. If the key already exists, its value is replaced. Extra keys before the final key/value (Dart Sass) update a nested map along that path.
No. It returns a copy. Reassign if you need to keep the result: $tokens: map.set($tokens, "primary", #1d4ed8).
Yes on Dart Sass: map.set($map, "a", "b", "c", $value) walks a → b and sets c to $value. Missing keys along the path become empty maps.
map.set updates one key (or one nested leaf). map.merge combines two whole maps. Use set for a single write; use merge when overlaying many keys at once.
No. Unlike map-get or map-remove, map.set is module-only. Load it with @use "sass:map" (or @use "sass:map" as * and call set()).
Official docs: if any key in the path is missing or points to a non-map, Sass sets that key to an empty map so the path can continue, then applies the final set.