Skip to content

[css-mixins-1] Allow typed custom properties inside custom functions #12317

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

Open
romainmenke opened this issue Jun 11, 2025 · 1 comment
Open

Comments

@romainmenke
Copy link
Member

See: #12315

I also found it a bit surprising that there is no way to have local typed custom properties. (except result)

@property --x {
  syntax: "<color>";
  inherits: true;
  initial-value: pink;
}

@function --foo() returns <color> {
  --x: rgb(255 0 0);
  
  result: if(
    style(--x: red): green;
    else: black;
  );
}

* {
  background-color: --foo(); /* black */
}

What was the original motivation to make everything untyped inside custom functions?

Because values are resolved in imaginary child elements nothing leaks out when a function is evaluated.
I can imagine that when the types are preserved it is possible to break custom functions by registering seemingly unrelated properties.

So maybe it should be possible to do local registrations?

@tabatkins
Copy link
Member

What was the original motivation to make everything untyped inside custom functions?

To avoid locals inside of functions having to be aware of all properties defined outside, or having to be defensively named to avoid collisions.

It would suck to write a re-usable function that used a local --foo variable to hold some intermediate calculation, and have that function straight up fail to work, unpredictably, on certain pages because that page also uses --foo for something and registered it with an incompatible type.

Also, arguments establish local variables, and they have a type, which has no need to be consistent with outside registrations either.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants