Skip to content

Commit

Permalink
Allow global Sass function colliding with CSS native functions to use…
Browse files Browse the repository at this point in the history
… 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
  • Loading branch information
Goodwine committed Apr 10, 2023
1 parent 283bdc0 commit e68818a
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 3 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,11 @@
* Deprecate the use of multiple `!global` or `!default` flags on the same
variable. This deprecation is named `duplicate-var-flags`.

* Allow special numbers like `var()` or `calc()` in the global functions:
`grayscale()`, `invert()`, `saturate()`, and `opacity()`. These are also
native CSS `filter` functions. This is in addition to number values which were
already allowed.

## 1.61.0

* **Potentially breaking change:** Drop support for End-of-Life Node.js 12.
Expand Down
13 changes: 10 additions & 3 deletions lib/src/functions/color.dart
Original file line number Diff line number Diff line change
Expand Up @@ -51,12 +51,13 @@ final global = UnmodifiableListView([

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

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

Expand Down Expand Up @@ -111,7 +112,8 @@ final global = UnmodifiableListView([
}),

_function("grayscale", r"$color", (arguments) {
if (arguments[0] is SassNumber) {
if (arguments[0] is SassNumber || arguments[0].isSpecialNumber) {
// Use the native CSS `grayscale` filter function.
return _functionString('grayscale', arguments);
}

Expand Down Expand Up @@ -143,6 +145,10 @@ final global = UnmodifiableListView([

BuiltInCallable.overloadedFunction("saturate", {
r"$amount": (arguments) {
if (arguments[0] is SassNumber || arguments[0].isSpecialNumber) {
// Use the native CSS `saturate` filter function.
return _functionString("saturate", arguments);
}
var number = arguments[0].assertNumber("amount");
return SassString("saturate(${number.toCssString()})", quotes: false);
},
Expand Down Expand Up @@ -204,7 +210,8 @@ final global = UnmodifiableListView([
}),

_function("opacity", r"$color", (arguments) {
if (arguments[0] is SassNumber) {
if (arguments[0] is SassNumber || arguments[0].isSpecialNumber) {
// Use the native CSS `opacity` filter function.
return _functionString("opacity", arguments);
}

Expand Down

0 comments on commit e68818a

Please sign in to comment.