Skip to content

Commit e68818a

Browse files
authored
Allow global Sass function colliding with CSS native functions to use CSS variables (#1926)
* Allow global Sass function colliding with CSS native functions to use CSS variables Many Sass functions are available globally even without loading their module. Some of these are also valid CSS native functions. Sass performs validations which disallow the use of CSS variables because the arguments are asserted a given type of value. For these collisions allow the use of CSS variables and in such cases assume the entire function call is meant to be the CSS native function rather than the global Sass function. Fixes sass/sass#3507 * Also allow for special numbers, not only for var() * add changelog oops
1 parent 283bdc0 commit e68818a

File tree

2 files changed

+15
-3
lines changed

2 files changed

+15
-3
lines changed

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,11 @@
33
* Deprecate the use of multiple `!global` or `!default` flags on the same
44
variable. This deprecation is named `duplicate-var-flags`.
55

6+
* Allow special numbers like `var()` or `calc()` in the global functions:
7+
`grayscale()`, `invert()`, `saturate()`, and `opacity()`. These are also
8+
native CSS `filter` functions. This is in addition to number values which were
9+
already allowed.
10+
611
## 1.61.0
712

813
* **Potentially breaking change:** Drop support for End-of-Life Node.js 12.

lib/src/functions/color.dart

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,12 +51,13 @@ final global = UnmodifiableListView([
5151

5252
_function("invert", r"$color, $weight: 100%", (arguments) {
5353
var weight = arguments[1].assertNumber("weight");
54-
if (arguments[0] is SassNumber) {
54+
if (arguments[0] is SassNumber || arguments[0].isSpecialNumber) {
5555
if (weight.value != 100 || !weight.hasUnit("%")) {
5656
throw "Only one argument may be passed to the plain-CSS invert() "
5757
"function.";
5858
}
5959

60+
// Use the native CSS `invert` filter function.
6061
return _functionString("invert", arguments.take(1));
6162
}
6263

@@ -111,7 +112,8 @@ final global = UnmodifiableListView([
111112
}),
112113

113114
_function("grayscale", r"$color", (arguments) {
114-
if (arguments[0] is SassNumber) {
115+
if (arguments[0] is SassNumber || arguments[0].isSpecialNumber) {
116+
// Use the native CSS `grayscale` filter function.
115117
return _functionString('grayscale', arguments);
116118
}
117119

@@ -143,6 +145,10 @@ final global = UnmodifiableListView([
143145

144146
BuiltInCallable.overloadedFunction("saturate", {
145147
r"$amount": (arguments) {
148+
if (arguments[0] is SassNumber || arguments[0].isSpecialNumber) {
149+
// Use the native CSS `saturate` filter function.
150+
return _functionString("saturate", arguments);
151+
}
146152
var number = arguments[0].assertNumber("amount");
147153
return SassString("saturate(${number.toCssString()})", quotes: false);
148154
},
@@ -204,7 +210,8 @@ final global = UnmodifiableListView([
204210
}),
205211

206212
_function("opacity", r"$color", (arguments) {
207-
if (arguments[0] is SassNumber) {
213+
if (arguments[0] is SassNumber || arguments[0].isSpecialNumber) {
214+
// Use the native CSS `opacity` filter function.
208215
return _functionString("opacity", arguments);
209216
}
210217

0 commit comments

Comments
 (0)