Skip to content

Commit

Permalink
Add deprecation messages for color arithmetic
Browse files Browse the repository at this point in the history
  • Loading branch information
xzyfer committed Apr 26, 2018
1 parent 0bc35e3 commit 578d502
Showing 1 changed file with 24 additions and 0 deletions.
24 changes: 24 additions & 0 deletions src/operators.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,22 @@ namespace Sass {
bool lte(Expression_Obj lhs, Expression_Obj rhs) { return cmp(lhs, rhs, Sass_OP::LTE) || eq(lhs, rhs); }
bool gte(Expression_Obj lhs, Expression_Obj rhs) { return !cmp(lhs, rhs, Sass_OP::GTE) || eq(lhs, rhs); }

/* colour math deprecation warning */
void op_color_deprecation(enum Sass_OP op, std::string lsh, std::string rhs, const ParserState& pstate)
{
std::string op_str(
op == Sass_OP::ADD ? "plus" :
op == Sass_OP::DIV ? "div" :
op == Sass_OP::SUB ? "minus" :
op == Sass_OP::MUL ? "times" : ""
);

std::string msg("The operation `" + lsh + " " + op_str + " " + rhs + "` is deprecated and will be an error in future versions.");
std::string tail("Consider using Sass's color functions instead.\nhttp://sass-lang.com/documentation/Sass/Script/Functions.html#other_color_functions");

deprecated(msg, tail, false, pstate);
}

/* static function, throws OperationError, has no traces but optional pstate for returned value */
Value_Ptr op_strings(Sass::Operand operand, Value& lhs, Value& rhs, struct Sass_Inspect_Options opt, const ParserState& pstate, bool delayed)
{
Expand Down Expand Up @@ -107,6 +123,8 @@ namespace Sass {
/* static function, throws OperationError, has no traces but optional pstate for returned value */
Value_Ptr op_colors(enum Sass_OP op, const Color& lhs, const Color& rhs, struct Sass_Inspect_Options opt, const ParserState& pstate, bool delayed)
{
op_color_deprecation(op, lhs.to_string(), rhs.to_string(), pstate);

if (lhs.a() != rhs.a()) {
throw Exception::AlphaChannelsNotEqual(&lhs, &rhs, op);
}
Expand Down Expand Up @@ -195,6 +213,9 @@ namespace Sass {
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)
{
double lval = lhs.value();

op_color_deprecation(op, lhs.to_string(), rhs.to_string(), pstate);

switch (op) {
case Sass_OP::ADD:
case Sass_OP::MUL: {
Expand Down Expand Up @@ -223,6 +244,9 @@ namespace Sass {
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)
{
double rval = rhs.value();

op_color_deprecation(op, lhs.to_string(), rhs.to_string(), pstate);

if (op == Sass_OP::DIV && rval == 0) {
// comparison of Fixnum with Float failed?
throw Exception::ZeroDivisionError(lhs, rhs);
Expand Down

0 comments on commit 578d502

Please sign in to comment.