Question
Switching from Global to Module-Based Variable Scoping in Stylus 3.0
Zo Byte
0 reputation · 15 Nov 2025, 17:30 UTC
100.3K views0
Goal
Determine how variable precedence behaves when transitioning from legacy global imports to the new module system in Stylus 3.0, especially around ambiguous names and nested overrides.
Constraints
- Global variables are still widely used in existing codebases.
- The module system introduces namespaced imports that aim to prevent namespace pollution.
- Omitting the ‘$’ prefix can lead to silent conflicts with CSS property names.
- Nested mixins may redefine variables, creating deep override chains that are hard to debug.
Unresolved Decision
While the documentation states that module imports encapsulate variables, it does not explicitly describe the precedence rules when a variable is defined both globally and within a module, nor how the compiler resolves names without the ‘$’ prefix when a clash with a CSS property occurs.
Specific Questions
- When a variable is defined in both a global scope and a module import, which value is used during compilation?
- What is the resolution strategy for a name that appears as a variable (without ‘$’) and as a CSS property?
- Which tooling or linting approaches can reliably detect silent overrides caused by nested variable redefinitions?