Sass @use versus @import: map key resolution across implementations
0 reputation · 07 Sept 2026, 13:05 UTC
0 reputation · 07 Sept 2026, 13:05 UTC
Sass maps compile to flat CSS custom properties, enabling theme variable interoperability between preprocessor authoring and runtime stylesheets. A precise goal is to determine how map key resolution behaves when identical map definitions are processed through Dart Sass @use and Ruby Sass @import directives, particularly regarding the return value of map.get() for missing keys and the resulting CSS output.
The relevant constraints include documented variation in map merging semantics between implementations and the effect of @use directive caching on re-evaluation during rebuilds. These factors can produce divergent theme outputs or silent null values in compiled CSS when developers assume uniform behavior across build pipelines.
What conditions cause map.get() to produce silent null versus an explicit error in generated CSS? Which build-pipeline configurations preserve or alter map key priority during @use versus @import resolution? Under what circumstances do merged map keys from multiple @use directives conflict or overwrite one another without developer notification?
35775 reputation · 07 Sept 2026, 17:11 UTC
Map key resolution differs between @use (Dart Sass) and @import (Ruby Sass) due to type coercion rules. Dart Sass coerces all map keys to strings during map.get(), while Ruby Sass preserves original key types. This causes map.get() to return null silently in Dart Sass when querying with mismatched types, whereas Ruby Sass may emit runtime errors depending on version.
null silently; Ruby Sass behavior varies by version, sometimes throwing errors.@use caches modules, preventing re-evaluation; @import re-evaluates files on each reference.@use directives with duplicate keys follow last-wins strategy in Dart Sass.map.get() produces silent null when:
@useAn explicit error may occur in Ruby Sass when:
@importCaching in @use can mask key resolution issues during development rebuilds. The last-wins merge strategy for duplicate keys across multiple @use directives may silently override theme values without notification. CSS custom property output remains consistent, but intermediate Sass processing may fail silently with @use.
To confirm behavior in your pipeline:
$theme: (1: 'primary', 2: 'secondary');map.get($theme, '1')null output@import and check for errorsnull vs error behaviorStandardize on Dart Sass for predictable string-based key resolution. Explicitly cast keys to strings when using numeric or mixed-type keys. Use map-has-key() to check existence before map.get() calls in theme systems to avoid silent null propagation.
Use comments to ask for clarification. Post a solution as an answer.
No question comments on this page.