sass/spec/declarations.md
2024-04-23 16:41:50 -07:00

2.2 KiB

Declarations

Table of Contents

Syntax

Declaration         ::= StandardDeclaration | CustomDeclaration
StandardDeclaration ::= InterpolatedIdentifier¹ ':' (Value | Value? '{' Statements '}')
CustomDeclaration   ::= InterpolatedIdentifier² ':' InterpolatedDeclarationValue

  1. This may not begin with "--".
  2. This must begin with "--".

Definitions

Current Declaration Name

The current declaration name is the innermost value declared as such when executing a declaration.

Semantics

To execute a declaration declaration:

  • Let parent-name be the current declaration name, if one exists.

  • If name is set and declaration is a CustomDeclaration, throw an error.

  • Let name be the result of evaluating the all interpolation in declaration's name.

  • If parent-name exists, set name to parent-name + "-" + name.

  • Declare name as the current declaration name for the duration of executing declaration.

  • If declaration has a Value:

    • Let value be the result of evaluating that Value.
  • Otherwise, if declaration is a CustomDeclaration:

    • Let value be an unquoted string whose value is the result of evaluating declaration's InterpolatedDeclarationValue.

    • If value is empty, throw an error.

      Note that value being only whitespace is allowed, including --foo: ;.

  • Let parent be the current style rule, keyframe block, or at-rule; or the innermost if multiple exist.

    Parsing guarantees that a declaration will have at least one parent.

  • If value is set, and it's neither null nor an empty unquoted string:

    • Let css be a CSS declaration with name name and value value.

    • Append css to parent.

  • Evaluate each child in declaration's Statements if it exists.