sass/spec/at-rules/function.md
2024-06-17 17:49:23 -07:00

1.8 KiB

@function

Table of Contents

Syntax

FunctionRule ::= '@function' <ident-token> ArgumentDeclaration '{' Statements '}'

No whitespace is allowed between the Identifier and the ArgumentDeclaration in FunctionRule.

Semantics

To execute a @function rule rule:

  • Let name be the value of rule's Identifier.

  • If name begins with --, throw an error.

  • If name is calc, element, expression, url, and, or, or not, or if name has a vendor prefix and the unprefixed identifier is one of those strings, throw an error.

  • Let parent be the current scope.

  • Let function be a function named name which does the following when executed with args:

    • With the current scope set to an empty scope with parent as its parent:

      • Evaluate args with rule's ArgumentDeclaration.

      • Execute each statement in rule.

      • Return the value from the @return rule if one was executed, or throw an error if no @return rule was executed.

  • If rule is outside of any block of statements:

    • If name doesn't begin with - or _, set the current module's function name to function.

      This overrides the previous definition, if one exists.

    • Set the current import context's function name to function.

      This happens regardless of whether or not it begins with - or _.

  • Otherwise, set the current scope's function name to function.