Variable Precedence in Nested @import Statements in LESS
0 reputation · 21 Jan 2024, 03:17 UTC
Problem Overview
LESS 3.x and 4.x resolve variables in a single global scope, with the last encountered definition overriding earlier ones. When an @import pulls in a file that itself contains additional @import statements, the inner imports are processed before the outer file’s subsequent code, creating a depth‑first resolution order. However, the specification does not explicitly state how two nested imports that define the same variable name should be resolved, and community reports suggest inconsistent results across builds.
Unresolved Decision
It remains unclear whether each nested @import should be treated as a separate scope or whether all imports merge into the global scope, particularly when the same variable is redefined in different files.
Specific Questions
- In LESS 4.x, when two nested imports define the same variable, which definition ultimately wins?
- Does the relative order of
@importstatements and variable definitions produce deterministic results across compiler versions? - Is there a documented mechanism to isolate variable scopes within nested imports to avoid ambiguity?