diff --git a/README.md b/README.md index 7689094..0e75b18 100644 --- a/README.md +++ b/README.md @@ -90,7 +90,7 @@ These numbers come from a default run of the Sass specification as shown above. ``` 2021-07-24 -PASSING: 4018 -FAILING: 2238 +PASSING: 4177 +FAILING: 2079 TOTAL: 6256 ``` diff --git a/src/builtin/functions/color/rgb.rs b/src/builtin/functions/color/rgb.rs index a359146..0f59048 100644 --- a/src/builtin/functions/color/rgb.rs +++ b/src/builtin/functions/color/rgb.rs @@ -154,20 +154,23 @@ fn inner_rgb(name: &'static str, mut args: CallArgs, parser: &mut Parser) -> Sas Ok(Value::Color(Box::new(color))) } else if len == 2 { - let color = match args.get_err(0, "color")? { + let color = args.get_err(0, "color")?; + let alpha = args.get_err(1, "alpha")?; + + if color.is_special_function() || (alpha.is_special_function() && !color.is_color()) { + return Ok(Value::String( + format!( + "{}({})", + name, + Value::List(vec![color, alpha], ListSeparator::Comma, Brackets::None) + .to_css_string(args.span(), false)? + ), + QuoteKind::None, + )); + } + + let color = match color { Value::Color(c) => c, - v if v.is_special_function() => { - let alpha = args.get_err(1, "alpha")?; - return Ok(Value::String( - format!( - "{}({}, {})", - name, - v.to_css_string(args.span(), parser.options.is_compressed())?, - alpha.to_css_string(args.span(), parser.options.is_compressed())? - ), - QuoteKind::None, - )); - } v => { return Err(( format!("$color: {} is not a color.", v.inspect(args.span())?), @@ -176,7 +179,22 @@ fn inner_rgb(name: &'static str, mut args: CallArgs, parser: &mut Parser) -> Sas .into()) } }; - let alpha = match args.get_err(1, "alpha")? { + + if alpha.is_special_function() { + return Ok(Value::String( + format!( + "{}({}, {}, {}, {})", + name, + color.red().to_string(false), + color.green().to_string(false), + color.blue().to_string(false), + alpha.to_css_string(args.span(), false)?, + ), + QuoteKind::None, + )); + } + + let alpha = match alpha { Value::Dimension(Some(n), Unit::None, _) => n, Value::Dimension(Some(n), Unit::Percent, _) => n / Number::from(100), Value::Dimension(None, ..) => todo!(), @@ -190,19 +208,6 @@ fn inner_rgb(name: &'static str, mut args: CallArgs, parser: &mut Parser) -> Sas ) .into()) } - v if v.is_special_function() => { - return Ok(Value::String( - format!( - "{}({}, {}, {}, {})", - name, - color.red().to_string(parser.options.is_compressed()), - color.green().to_string(parser.options.is_compressed()), - color.blue().to_string(parser.options.is_compressed()), - v.to_css_string(args.span(), parser.options.is_compressed())? - ), - QuoteKind::None, - )); - } v => { return Err(( format!("$alpha: {} is not a number.", v.inspect(args.span())?), diff --git a/src/value/mod.rs b/src/value/mod.rs index 70a9bfd..fea0031 100644 --- a/src/value/mod.rs +++ b/src/value/mod.rs @@ -344,6 +344,10 @@ impl Value { } } + pub fn is_color(&self) -> bool { + matches!(self, Value::Color(..)) + } + pub fn is_special_function(&self) -> bool { match self { Value::String(s, QuoteKind::None) => is_special_function(s), diff --git a/tests/color.rs b/tests/color.rs index 562807c..700ead8 100644 --- a/tests/color.rs +++ b/tests/color.rs @@ -762,6 +762,16 @@ test!( "a {\n color: hsla(var(--foo));\n}\n", "a {\n color: hsla(var(--foo));\n}\n" ); +test!( + rgb_special_fn_2_arg_first_non_color, + "a {\n color: rgb(1, var(--foo));\n}\n", + "a {\n color: rgb(1, var(--foo));\n}\n" +); +test!( + rgb_special_fn_2_arg_first_is_color, + "a {\n color: rgb(rgb(1%, 1, 1), var(--foo));;\n}\n", + "a {\n color: rgb(3, 1, 1, var(--foo));\n}\n" +); test!( #[ignore = "we do not check if interpolation occurred"] interpolated_named_color_is_not_color,