4.2 KiB
@mixin
, @include
, and @content
Table of Contents
@mixin
Syntax
MixinRule ::= '@mixin' <ident-token> ArgumentDeclaration? '{' Statements '}'
No whitespace is allowed between the Identifier
and the ArgumentDeclaration
in MixinRule
.
Semantics
To execute a @mixin
rule rule
:
-
Let
name
be the value ofrule
'sIdentifier
. -
If
name
begins with--
, throw an error. -
Let
parent
be the current scope. -
Let
mixin
be a mixin namedname
which accepts a content block ifrule
contains a@content
rule. To execute this mixin withargs
:-
With the current scope set to an empty scope with
parent
as its parent:-
Evaluate
args
withrule
'sArgumentDeclaration
. -
Execute each statement in
rule
.
-
-
-
If
rule
is outside of any block of statements:-
If
name
doesn't begin with-
or_
, set the current module's mixinname
tomixin
.This overrides the previous definition, if one exists.
-
Set the current import context's mixin
name
tomixin
.This happens regardless of whether or not it begins with
-
or_
.
-
-
Otherwise, set the current scope's mixin
name
tomixin
.This overrides the previous definition, if one exists.
@include
Syntax
IncludeRule ::= '@include' NamespacedIdentifier ArgumentInvocation? ContentBlock? ContentBlock ::= UsingDeclaration? '{' Statements '}' UsingDeclaration ::= 'using' ArgumentDeclaration
No whitespace is allowed between the NamespacedIdentifier
and the
ArgumentInvocation
in IncludeRule
.
Semantics
To execute an @include
rule rule
:
-
Let
name
berule
'sNamespacedIdentifier
. -
Let
mixin
be the result of resolving a mixin namedname
. If this returns null, throw an error. -
Execute
mixin
withrule
'sArgumentInvocation
.
@content
The @content
rule runs a block of styles provided by the user who invoked the
current mixin.
Syntax
ContentRule ::= '@content' ArgumentInvocation?
As with all statements, a ContentRule
must be separated from other statements
with a semicolon.
Semantics
To execute a @content
rule content
within a mixin that's invoked with
an @include
rule include
:
@content
rules are syntactically guaranteed to only appear in mixin bodies, and mixins must be invoked using@include
, soinclude
is guaranted to exist.
-
Let
invocation
becontent
'sArgumentInvocation
, or an invocation with no arguments ifcontent
has noArgumentInvocation
.This means that
@content
and@content()
are interpreted identically. -
Let
declaration
beinclude
'sUsingDeclaration
'sArgumentDeclaration
, or a declaration with no arguments ifinclude
has noUsingDeclaration
.This means that
@include foo { ... }
and@include foo using () { ... }
are interpreted identically. -
Let
arguments
be the result of applyinginvocation
todeclaration
.This means
arguments
is a mapping from variable names to values. Ifinvocation
isn't a valid invocation ofdeclaration
, this will throw an error that should be surfaced to the user. -
If
include
has noContentBlock
, do nothing.Exiting here rather than earlier means that
@content(value)
is an error ifinclude
has no content block. -
Otherwise, let
scope
be a new scope that's a child ofinclude
's scope. -
For each pair
variable
andvalue
inarguments
:- Set
variable
tovalue
inscope
.
- Set
-
Execute
include
'sContentBlock
statements inscope
.