Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support var() with an empty fallback #3338

Merged
merged 1 commit into from
Jun 21, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
34 changes: 28 additions & 6 deletions spec/functions.md
Original file line number Diff line number Diff line change
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