Skip to content

Commit b9fb0ab

Browse files
authored
Quote channel names in color functions (#2218)
1 parent 470447f commit b9fb0ab

File tree

1 file changed

+11
-10
lines changed

1 file changed

+11
-10
lines changed

lib/src/functions/color.dart

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -448,11 +448,8 @@ final module = BuiltInModule("color", functions: <Callable>[
448448
r"$color, $channel",
449449
(arguments) => SassBoolean(arguments[0]
450450
.assertColor("color")
451-
.isChannelMissing(
452-
(arguments[1].assertString("channel")..assertQuoted("channel"))
453-
.text,
454-
colorName: "color",
455-
channelName: "channel"))),
451+
.isChannelMissing(_channelName(arguments[1]),
452+
colorName: "color", channelName: "channel"))),
456453

457454
_function(
458455
"is-in-gamut",
@@ -475,7 +472,7 @@ final module = BuiltInModule("color", functions: <Callable>[
475472

476473
_function("channel", r"$color, $channel, $space: null", (arguments) {
477474
var color = _colorInSpace(arguments[0], arguments[2]);
478-
var channelName = arguments[1].assertString("channel").text.toLowerCase();
475+
var channelName = _channelName(arguments[1]);
479476
if (channelName == "alpha") return SassNumber(color.alpha);
480477

481478
var channelIndex = color.space.channels
@@ -511,10 +508,8 @@ final module = BuiltInModule("color", functions: <Callable>[
511508
"is-powerless",
512509
r"$color, $channel, $space: null",
513510
(arguments) => SassBoolean(_colorInSpace(arguments[0], arguments[2])
514-
.isChannelPowerless(
515-
arguments[1].assertString("channel").text.toLowerCase(),
516-
colorName: "color",
517-
channelName: "channel"))),
511+
.isChannelPowerless(_channelName(arguments[1]),
512+
colorName: "color", channelName: "channel"))),
518513

519514
_complement,
520515

@@ -1510,6 +1505,12 @@ String _suggestScaleAndAdjust(
15101505
return suggestion + "color.adjust(\$color, \$$channelName: $difference)";
15111506
}
15121507

1508+
/// Asserts that `value` is an unquoted string and throws an error if it's not.
1509+
///
1510+
/// Assumes that `value` comes from a parameter named `$channel`.
1511+
String _channelName(Value value) =>
1512+
(value.assertString("channel")..assertQuoted("channel")).text.toLowerCase();
1513+
15131514
/// Like [BuiltInCallable.function], but always sets the URL to
15141515
/// `sass:color`.
15151516
BuiltInCallable _function(

0 commit comments

Comments
 (0)