Skip to content

Commit c43a10e

Browse files
andruudAnders Hartvoll Ruud
andauthored
[css-mixins-1] Describe custom function cycles (#11446)
Co-authored-by: Anders Hartvoll Ruud <andruud@google.com>
1 parent f1f3672 commit c43a10e

File tree

1 file changed

+76
-1
lines changed

1 file changed

+76
-1
lines changed

css-mixins-1/Overview.bs

Lines changed: 76 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ Default Highlight: css
1717
spec:infra; type:dfn; text:list
1818
spec:css-properties-values-api; type:dfn; text:supported syntax component name
1919
spec:css-properties-values-api; type:dfn; text:syntax component
20+
spec:css-syntax-3; type:dfn; text:declaration
2021
spec:css-syntax-3; type:dfn; text:descriptor;
2122
spec:css-values-4; type:dfn; text:keyword;
2223
spec:css-values-4; type:dfn; text:identifier;
@@ -417,7 +418,81 @@ is the [=guaranteed-invalid value=].
417418
Cycles {#cycles}
418419
----------------
419420

420-
Issue: TODO
421+
The ''result'' descriptor and [=local variables=]
422+
within a [=custom function=]
423+
may reference other [=custom functions=] or [=custom properties=],
424+
and may therefore create [[css-variables-1#cycles|cycles]].
425+
426+
For each element, add a node for every specified [=custom function=]
427+
to the graph described in [[css-variables-1#cycles]];
428+
add a node for each [=local variable=]
429+
defined within each of those functions;
430+
then, for each [=custom function=] <var>func</var>, add edges as follows:
431+
432+
* From <var>func</var> to any [=custom function=]
433+
referenced by a <<dashed-function>> within <var>func</var>'s body.
434+
* From <var>func</var> to any [=custom property=] or [=local variable=]
435+
referenced by a ''var()'' within <var>func</var>'s body.
436+
* To <var>func</var> from any [=custom property=] or [=local variable=]
437+
that references <var>func</var>
438+
using a <<dashed-function>>.
439+
440+
A <<dashed-function>> referencing a [=custom function=]
441+
which is part of a cycle
442+
makes the containing [=declaration=] [=invalid at computed-value time=].
443+
444+
Note: Cycles are disallowed even through branches that are not taken
445+
during execution.
446+
447+
<div class='example'>
448+
In the following,
449+
<code>--foo()</code> is in a cycle with itself,
450+
even though the media query never evaluates to "true":
451+
452+
<pre class='lang-css'>
453+
@function --foo(--x) {
454+
@media (unknown-feature) {
455+
result: --foo(42);
456+
}
457+
result: 1;
458+
}
459+
</pre>
460+
461+
Similarly,
462+
<code>--bar()</code> is in a cycle with itself,
463+
even though the local variable <code>--x</code> is never referenced:
464+
465+
<pre class='lang-css'>
466+
@function --bar() {
467+
--x: --bar();
468+
result: 1;
469+
}
470+
</pre>
471+
</div>
472+
473+
<div class='example'>
474+
The function <code>--baz()</code> is not in a cycle in the example below:
475+
even though <code>var(--x)</code> and <code>var(--y)</code> appear in the function body,
476+
they refer to a [=function parameter=] and [=local variable=], respectively.
477+
The [=custom properties=] <code>--x</code> and <code>--y</code>
478+
both reference <code>--baz()</code>, but that's fine:
479+
those [=custom properties=] are not referenced within <code>--baz()</code>.
480+
481+
<pre class='lang-css'>
482+
@function --baz(--x) {
483+
--y: 10px;
484+
result: calc(var(--x) + var(--y));
485+
}
486+
487+
div {
488+
--x: --baz(1px);
489+
--y: --baz(2px);
490+
width: var(--x); /* 11px */
491+
height: var(--y); /* 12px */
492+
}
493+
</pre>
494+
</div>
495+
421496

422497
<!-- Big Text: execution
423498

0 commit comments

Comments
 (0)