@@ -54,6 +54,22 @@ namespace Sass {
5454 bool lte (Expression_Obj lhs, Expression_Obj rhs) { return cmp (lhs, rhs, Sass_OP::LTE) || eq (lhs, rhs); }
5555 bool gte (Expression_Obj lhs, Expression_Obj rhs) { return !cmp (lhs, rhs, Sass_OP::GTE) || eq (lhs, rhs); }
5656
57+ /* colour math deprecation warning */
58+ void op_color_deprecation (enum Sass_OP op, std::string lsh, std::string rhs, const ParserState& pstate)
59+ {
60+ std::string op_str (
61+ op == Sass_OP::ADD ? " plus" :
62+ op == Sass_OP::DIV ? " div" :
63+ op == Sass_OP::SUB ? " minus" :
64+ op == Sass_OP::MUL ? " times" : " "
65+ );
66+
67+ std::string msg (" The operation `" + lsh + " " + op_str + " " + rhs + " ` is deprecated and will be an error in future versions." );
68+ std::string tail (" Consider using Sass's color functions instead.\n http://sass-lang.com/documentation/Sass/Script/Functions.html#other_color_functions" );
69+
70+ deprecated (msg, tail, false , pstate);
71+ }
72+
5773 /* static function, throws OperationError, has no traces but optional pstate for returned value */
5874 Value_Ptr op_strings (Sass::Operand operand, Value& lhs, Value& rhs, struct Sass_Inspect_Options opt, const ParserState& pstate, bool delayed)
5975 {
@@ -107,12 +123,16 @@ namespace Sass {
107123 /* static function, throws OperationError, has no traces but optional pstate for returned value */
108124 Value_Ptr op_colors (enum Sass_OP op, const Color& lhs, const Color& rhs, struct Sass_Inspect_Options opt, const ParserState& pstate, bool delayed)
109125 {
126+
110127 if (lhs.a () != rhs.a ()) {
111128 throw Exception::AlphaChannelsNotEqual (&lhs, &rhs, op);
112129 }
113- if (op == Sass_OP::DIV && (!rhs.r () || !rhs.g () || !rhs.b ())) {
130+ if (( op == Sass_OP::DIV || op == Sass_OP::MOD) && (!rhs.r () || !rhs.g () || !rhs.b ())) {
114131 throw Exception::ZeroDivisionError (lhs, rhs);
115132 }
133+
134+ op_color_deprecation (op, lhs.to_string (), rhs.to_string (), pstate);
135+
116136 return SASS_MEMORY_NEW (Color,
117137 pstate,
118138 ops[op](lhs.r (), rhs.r ()),
@@ -195,9 +215,11 @@ namespace Sass {
195215 Value_Ptr op_number_color (enum Sass_OP op, const Number& lhs, const Color& rhs, struct Sass_Inspect_Options opt, const ParserState& pstate, bool delayed)
196216 {
197217 double lval = lhs.value ();
218+
198219 switch (op) {
199220 case Sass_OP::ADD:
200221 case Sass_OP::MUL: {
222+ op_color_deprecation (op, lhs.to_string (), rhs.to_string (opt), pstate);
201223 return SASS_MEMORY_NEW (Color,
202224 pstate,
203225 ops[op](lval, rhs.r ()),
@@ -208,6 +230,7 @@ namespace Sass {
208230 case Sass_OP::SUB:
209231 case Sass_OP::DIV: {
210232 std::string color (rhs.to_string (opt));
233+ op_color_deprecation (op, lhs.to_string (), color, pstate);
211234 return SASS_MEMORY_NEW (String_Quoted,
212235 pstate,
213236 lhs.to_string (opt)
@@ -223,10 +246,14 @@ namespace Sass {
223246 Value_Ptr op_color_number (enum Sass_OP op, const Color& lhs, const Number& rhs, struct Sass_Inspect_Options opt, const ParserState& pstate, bool delayed)
224247 {
225248 double rval = rhs.value ();
226- if (op == Sass_OP::DIV && rval == 0 ) {
249+
250+ if ((op == Sass_OP::DIV || op == Sass_OP::DIV) && rval == 0 ) {
227251 // comparison of Fixnum with Float failed?
228252 throw Exception::ZeroDivisionError (lhs, rhs);
229253 }
254+
255+ op_color_deprecation (op, lhs.to_string (), rhs.to_string (), pstate);
256+
230257 return SASS_MEMORY_NEW (Color,
231258 pstate,
232259 ops[op](lhs.r (), rval),
0 commit comments