The @forward
rule loads a module from a URL and adds its members to the
public API of the current module without making them available to use within the
current stylesheet.
The grammar for the @forward
rule is as follows:
ForwardRule ::= '@forward' QuotedString AsClause? (ShowClause | HideClause)? WithClause? AsClause ::= 'as' <ident-token> '*' ShowClause ::= 'show' MemberName (',' MemberName)* HideClause ::= 'hide' MemberName (',' MemberName)* WithClause ::= 'with' '(' ForwardWithArgument (',' ForwardWithArgument)* ','? ')' ForwardWithArgument ::= '$' Identifier ':' Expression '!default'? MemberName ::= '$'? <ident-token>
@forward
rules must be at the top level of the document, and must come before
any rules other than @charset
or @use
. The QuotedString
's contents, known
as the rule's URL, must be a valid URL string (for non-special base
URL). No whitespace is allowed after $
in MemberName
, or before *
in
AsClause
.
Note that
@forward
does not make any APIs available to the current module; that is purely the domain of@use
. It does include the forwarded module's CSS tree, but it's not visible to@extend
without also using the module.
To execute a @forward
rule rule
:
-
If
rule
has anAsClause
with identifierprefix
:-
Let
rule-config
be an empty configuration with the same opaque ID as the current configuration. -
For each variable
variable
in the current configuration:-
If
variable
's name begins withprefix
:-
Let
suffix
be the portion ofvariable
's name afterprefix
. -
Add a variable to
rule-config
with the namesuffix
and with the same value asvariable
.
-
-
-
-
Otherwise, let
rule-config
be the current configuration. -
If
rule
has aWithClause
:-
Set
rule-config
to a copy of itself including its opaque ID. -
For each
ForwardWithArgument
argument
in this clause:-
If
argument
has a!default
flag and a variable exists inrule-config
with the same name asargument
's identifier, do nothing. -
Otherwise, let
value
be the result of evaluatingargument
's expression. -
Add a variable to
rule-config
with the same name asargument
's identifier, and withvalue
as its value.
-
-
-
Let
forwarded
be the result of loading the module withrule
's URL string andrule-config
. -
If
rule
has aWithClause
:-
For each
ForwardWithArgument
argument
in this clause:-
Let
variable
be the variable inmodule
with the same name asargument
's identifier. If no such variable exists, throw an error. -
If
variable
wasn't declared with a!default
flag, throw an error.
-
-
-
For every member
member
inforwarded
:-
Let
name
bemember
's name. -
If
rule
has anAsClause
as
, prependas
's identifier toname
(after the$
ifmember
is a variable). -
If there's a member defined at the top level of the current source file named
name
with the same type asmember
, do nothing. -
Otherwise, if
rule
has ashow
clause that doesn't includename
(including$
for variables), do nothing.It's not possible to show/hide a mixin without showing/hiding the equivalent function, or to do the reverse.
-
Otherwise, if
rule
has ahide
clause that does includename
(including$
for variables), do nothing. -
If another
@forward
rule's module has a member namedname
with the same type asmember
:-
If the other member is identical to
member
, do nothing. -
Otherwise, throw an error.
-
-
Otherwise, add
member
to the current module with the namename
.It's possible for the same member to be added to a given module multiple times if it's forwarded with different prefixes. All of these names refer to the same logical member, so for example if a variable gets set that change will appear for all of its names.
It's also possible for a module's members to have multiple prefixes added, if they're forwarded with prefixes multiple times.
-