Skip to content

Commit

Permalink
Support var() with an empty fallback
Browse files Browse the repository at this point in the history
See #3245
  • Loading branch information
nex3 committed Jun 16, 2022
1 parent 747d8d9 commit 13becfa
Showing 1 changed file with 28 additions and 6 deletions.
34 changes: 28 additions & 6 deletions spec/functions.md
Expand Up @@ -7,6 +7,8 @@
* [Special Variable String](#special-variable-string)
* [Syntax](#syntax)
* [Semantics](#semantics)
* [`EmptyFallbackVar`:](#emptyfallbackvar)
* [`FunctionCall`](#functioncall)
* [Global Functions](#global-functions)
* [`adjust-hue()`](#adjust-hue)
* [`alpha()`](#alpha)
Expand Down Expand Up @@ -48,19 +50,23 @@ matching is case-insensitive.
**FunctionExpression**¹ ::= [CssMinMax]
  | [SpecialFunctionExpression]
  | [CalculationExpression]
  | EmptyFallbackVar
  | FunctionCall
**FunctionCall**² ::= [NamespacedIdentifier] ArgumentInvocation
**EmptyFallbackVar**² ::= 'var(' Expression ',' ')'
**FunctionCall**⁴ ::= [NamespacedIdentifier] ArgumentInvocation
</pre></x>

[CssMinMax]: types/calculation.md#cssminmax
[SpecialFunctionExpression]: syntax.md#specialfunctionexpression
[CalculationExpression]: types/calculation.md#calculationexpression
[NamespacedIdentifier]: modules.md#syntax

1: If both `CssMinMax` and `FunctionCall` could be consumed, `CssMinMax`
takes precedence.
1: Both `CssMinMax` and `EmptyFallbackVar` take precedence over `FunctionCall`
if either could be consumed.

2: `FunctionCall` may not have any whitespace between the `NamespacedIdentifier`
2: `'var('` is matched case-insensitively.

4: `FunctionCall` may not have any whitespace between the `NamespacedIdentifier`
and the `ArgumentInvocation`. It may not start with [`SpecialFunctionName`],
`'calc('`, or `'clamp('` (case-insensitively).

Expand All @@ -77,14 +83,30 @@ No whitespace is allowed between the `NamespacedIdentifier` and the

## Semantics

### `EmptyFallbackVar`:

To evaluate an `EmptyFallbackVar` `call`:

* Let `argument` be the result of evaluating `call`'s `Expression`.

* Let `function` be the result of [resolving a function] named `'var'`.

[resolving a function]: modules.md#resolving-a-member

* If `function` is null, return an unquoted string consisting of `'var('`
followed by `argument`'s CSS representation followed by `',)'`.

* Return the result of calling `function` with `argument` as its first argument
and an empty unquoted string as its second argument.

### `FunctionCall`

To evaluate a `FunctionCall` `call`:

* Let `name` be `call`'s `NamespacedIdentifier`.

* Let `function` be the result of [resolving a function][] named `name`.

[resolving a function]: modules.md#resolving-a-member

* If `function` is null and `name` is not a plain `Identifier`, throw an error.

* If `function` is null, set it to the [global function](#global-functions)
Expand Down

0 comments on commit 13becfa

Please sign in to comment.