@@ -54,6 +54,22 @@ namespace Sass {
54
54
bool lte (Expression_Obj lhs, Expression_Obj rhs) { return cmp (lhs, rhs, Sass_OP::LTE) || eq (lhs, rhs); }
55
55
bool gte (Expression_Obj lhs, Expression_Obj rhs) { return !cmp (lhs, rhs, Sass_OP::GTE) || eq (lhs, rhs); }
56
56
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
+
57
73
/* static function, throws OperationError, has no traces but optional pstate for returned value */
58
74
Value_Ptr op_strings (Sass::Operand operand, Value& lhs, Value& rhs, struct Sass_Inspect_Options opt, const ParserState& pstate, bool delayed)
59
75
{
@@ -107,12 +123,16 @@ namespace Sass {
107
123
/* static function, throws OperationError, has no traces but optional pstate for returned value */
108
124
Value_Ptr op_colors (enum Sass_OP op, const Color& lhs, const Color& rhs, struct Sass_Inspect_Options opt, const ParserState& pstate, bool delayed)
109
125
{
126
+
110
127
if (lhs.a () != rhs.a ()) {
111
128
throw Exception::AlphaChannelsNotEqual (&lhs, &rhs, op);
112
129
}
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 ())) {
114
131
throw Exception::ZeroDivisionError (lhs, rhs);
115
132
}
133
+
134
+ op_color_deprecation (op, lhs.to_string (), rhs.to_string (), pstate);
135
+
116
136
return SASS_MEMORY_NEW (Color,
117
137
pstate,
118
138
ops[op](lhs.r (), rhs.r ()),
@@ -195,9 +215,11 @@ namespace Sass {
195
215
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)
196
216
{
197
217
double lval = lhs.value ();
218
+
198
219
switch (op) {
199
220
case Sass_OP::ADD:
200
221
case Sass_OP::MUL: {
222
+ op_color_deprecation (op, lhs.to_string (), rhs.to_string (opt), pstate);
201
223
return SASS_MEMORY_NEW (Color,
202
224
pstate,
203
225
ops[op](lval, rhs.r ()),
@@ -208,6 +230,7 @@ namespace Sass {
208
230
case Sass_OP::SUB:
209
231
case Sass_OP::DIV: {
210
232
std::string color (rhs.to_string (opt));
233
+ op_color_deprecation (op, lhs.to_string (), color, pstate);
211
234
return SASS_MEMORY_NEW (String_Quoted,
212
235
pstate,
213
236
lhs.to_string (opt)
@@ -223,10 +246,14 @@ namespace Sass {
223
246
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)
224
247
{
225
248
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 ) {
227
251
// comparison of Fixnum with Float failed?
228
252
throw Exception::ZeroDivisionError (lhs, rhs);
229
253
}
254
+
255
+ op_color_deprecation (op, lhs.to_string (), rhs.to_string (), pstate);
256
+
230
257
return SASS_MEMORY_NEW (Color,
231
258
pstate,
232
259
ops[op](lhs.r (), rval),
0 commit comments