question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Support CSS variables

See original GitHub issue

CSS Variables introduces the <any-value> production, and Sass should support it.

This production introduces some serious questions about how Sass should parse it. It’s general enough to allow practically any string, which means that treating it as a normal property would break CSS compatibility. For example, var-foo: 1 +; is valid CSS, but currently Sass would fail to parse it. Fundamentally, we need to decide what balance to strike between compatibility, programmability, and user expectations. Here are several options:

  1. The most compatible option would be to parse it exactly as specified in CSS and make no changes. For example, var-foo: $var would emit var-foo: $var literally, without replacing $var with its Sass value. This would make it impossible to assign variable values programmatically, though, as well as seriously violating user expectations.
  2. The most programmable option and the option that would be least surprising to users would be to parse these as any other property. This would be a much larger break with CSS compatibility than we’ve done before, though, which itself violates the user’s expectation that all CSS is valid SCSS.
  3. We could meet somewhere in the middle by allowing the use of #{} and possibly a single variable in <any-value> productions. This violates both compatibility, since $var is a valid CSS value that a user’s JavaScript might theoretically use, and user expectations, since e.g. var-foo: $var1, $var2, $var3 won’t work as expected. However, it will support most valid CSS and will allow variables to be created with mixins, albeit possibly with an ugly intermediate variable.
  4. We could try to parse the value as a plain SassScript value, and if it fails to parse treat it as an unparsed. This would mean that any syntax errors would be difficult to track down, and poses more serious compatibility issues than option 3, since var-foo: 1 + 2 will be treated very differently in Sass than in raw CSS.

I’m not sure what the best option is. If I had to choose now, I’d probably lean towards option 3, but I don’t really like any of them.

Issue Analytics

  • State:closed
  • Created 10 years ago
  • Reactions:3
  • Comments:39 (12 by maintainers)

github_iconTop GitHub Comments

8reactions
nazar-pccommented, Aug 11, 2015

Guys, this should be top priority thing. Since you’re declaring full CSS compatibility you’re lying already. Moreover, since Polymer 1.0 uses custom CSS mixins, it doesn’t seem to be possible to write in SCSS at all:

--some-mixin : {
    font-size   : 10px;
    font-weight : bold;
};

Code above whould be compiled to exactly the same thing. It seems that check for -- prefix should be simple enough to implement, and if -- prefix found - leave it as is on current level.

1reaction
Draccozcommented, Feb 17, 2016

I’ve read briefly all the above and still miss 1 use case. What if developer creates a SASS mixin to be used inside of SASS, but then will want to export that to be used outside (as CSS mixin). Ideally that would look like:

@mixin my-mixin {
  ...
}

:host {
  --my-mixin: {
    @include my-mixin;
  }
}

Sadly, none of the above would work, while this would be used a lot (I was actually in need of such thing myself). Any ideas if that will be possible and eventually when?

Read more comments on GitHub >

github_iconTop Results From Across the Web

CSS Variables (Custom Properties) | Can I use... Support ...
CSS Variables (Custom Properties). - CR. Permits the declaration and usage of cascading variables in stylesheets. Usage % of. all users, all tracked ......
Read more >
Using CSS custom properties (variables) - MDN Web Docs
Custom properties (sometimes referred to as CSS variables or cascading variables) are entities defined by CSS authors that contain specific ...
Read more >
Browser Compatibility of CSS Variables (Custom Properties)
CSS Variables (Custom Properties) on Chrome is fully supported on 49-106, partially supported on None of the versions, and not supported on 4-48 ......
Read more >
A user's guide to CSS variables – Increment: Frontend
CSS variables are currently supported for 93 percent of users globally. CSS variables are currently supported for 93 percent of users globally. If...
Read more >
CSS Variables - The var() function
The var() function is used to insert the value of a CSS variable. CSS variables have access to the DOM, which means that...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found