Variable ::= PlainVariable | NamespacedVariable PlainVariable ::= '$' <ident-token> NamespacedVariable ::= <ident-token> '.$' PublicIdentifier VariableDeclaration ::= Variable ':' Expression ('!global' | '!default')*
No whitespace is allowed after the $
in PlainVariable
or before or after
the .$
in NamespacedVariable
. Each of !global
and !default
is allowed
at most once in VariableDeclaration
. As with all statements, a
VariableDeclaration
must be separated from other statements with a semicolon.
A scope is a mapping from variable names to values. Every block of statements
delimited by {
and }
in SCSS or by indentation in the indented syntax has an
associated scope.
The global scope is the scope shared among the top level of all Sass files.
To execute a VariableDeclaration
declaration
:
-
Let
value
be the result of evaluatingdeclaration
'sExpression
. -
Let
name
bedeclaration
'sVariable
. -
Let
resolved
be the result of resolving a variable namedname
. -
If
name
is aNamespacedVariable
anddeclaration
has a!global
flag, throw an error. -
Otherwise, if
resolved
is a variable from a built-in module, throw an error. -
Otherwise, if
declaration
is outside of any block of statements, ordeclaration
has a!global
flag, orname
is aNamespacedVariable
:-
If
declaration
has a!default
flag,resolved
isn't null, andresolved
's value isn't null, do nothing. -
Otherwise, if
resolved
is a variable in another module:- Evaluate
declaration
's value and setresolved
's value to the result.
- Evaluate
-
Otherwise:
-
If
declaration
is outside of any block of statements, it has a!default
flag, andconfig
contains a variable namedname
whose value is not null:- Let
value
be the value ofconfig
's variable namedname
.
- Let
-
Otherwise, let
value
be the result of evaluatingdeclaration
's value. -
If
name
doesn't begin with-
or_
, add a variable with namename
and valuevalue
tomodule
.This overrides the previous definition, if one exists.
-
Add a variable with name
name
and valuevalue
toimport
.This also overrides the previous definition.
-
-
-
Otherwise, if
declaration
is within one or more blocks associated with@if
,@each
,@for
, and/or@while
rules and no other blocks:-
If
resolved
is not null:-
If
declaration
has a!default
flag andresolved
's value isn't null, do nothing. -
Otherwise, let
value
be the result of evaluatingdeclaration
's value. -
If
name
doesn't begin with-
or_
, add a variable with namename
and valuevalue
tomodule
.This overrides the previous definition, if one exists.
-
Add a variable with name
name
and valuevalue
toimport
.This also overrides the previous definition.
-
-
-
Otherwise, if
resolved
is null, get the innermost block containingdeclaration
and set its scope's variablename
tovalue
. -
Otherwise, set
resolved
's value tovalue
.
To evaluate a Variable
variable
:
-
Let
definition
be the result of resolving a variable namedvariable
. If this returns null, throw an error. -
Return
definition
's value.