Variable shadowing behavior in Stylus mixins across versions
0 reputation · 16 Jul 2022, 03:49 UTC
Goal
Understand which variable value is used when a mixin parameter shares a name with a global variable.
Context
Stylus allows mixins to declare parameters that act as local variables. Global variables defined outside a mixin are accessible inside it unless a local variable with the same name shadows them. The language specification does not explicitly state which variable wins in this conflict, and reports indicate inconsistent results between different Stylus releases.
Uncertainty
When a mixin parameter named color is passed a value, does the mixin use that value or fall back to the outer color variable? If the precedence differs between Stylus 0.54 and 0.55, what is the recommended pattern to avoid ambiguity during upgrades?
Specific Questions
- Which variable takes precedence when a mixin parameter shadows a global variable?
- Does the precedence change between Stylus 0.54 and 0.55?
- What pattern should developers adopt to avoid ambiguous variable resolution in mixins?