diff --git a/src/eval.cpp b/src/eval.cpp index 83e8a2d64..4985e5210 100644 --- a/src/eval.cpp +++ b/src/eval.cpp @@ -600,10 +600,6 @@ namespace Sass { switch (op_type) { case Sass_OP::EQ: return *l_n == *r_c ? bool_true : bool_false; case Sass_OP::NEQ: return *l_n == *r_c ? bool_false : bool_true; - case Sass_OP::LT: return *l_n < *r_c ? bool_true : bool_false; - case Sass_OP::GTE: return *l_n < *r_c ? bool_false : bool_true; - case Sass_OP::LTE: return *l_n < *r_c || *l_n == *r_c ? bool_true : bool_false; - case Sass_OP::GT: return *l_n < *r_c || *l_n == *r_c ? bool_false : bool_true; case Sass_OP::ADD: case Sass_OP::SUB: case Sass_OP::MUL: case Sass_OP::DIV: case Sass_OP::MOD: return Operators::op_number_color(op_type, *l_n, *r_c, ctx.c_options, b_in->pstate()); default: break; @@ -644,10 +640,6 @@ namespace Sass { switch (op_type) { case Sass_OP::EQ: return *l_c == *r_n ? bool_true : bool_false; case Sass_OP::NEQ: return *l_c == *r_n ? bool_false : bool_true; - case Sass_OP::LT: return *l_c < *r_n ? bool_true : bool_false; - case Sass_OP::GTE: return *l_c < *r_n ? bool_false : bool_true; - case Sass_OP::LTE: return *l_c < *r_n || *l_c == *r_n ? bool_true : bool_false; - case Sass_OP::GT: return *l_c < *r_n || *l_c == *r_n ? bool_false : bool_true; case Sass_OP::ADD: case Sass_OP::SUB: case Sass_OP::MUL: case Sass_OP::DIV: case Sass_OP::MOD: return Operators::op_color_number(op_type, *l_c, *r_n, ctx.c_options, b_in->pstate()); default: break; @@ -1271,13 +1263,6 @@ namespace Sass { Expression_Ptr Eval::operator()(String_Constant_Ptr s) { - if (!s->is_delayed() && name_to_color(s->value())) { - Color_Ptr c = SASS_MEMORY_COPY(name_to_color(s->value())); // copy - c->pstate(s->pstate()); - c->disp(s->value()); - c->is_delayed(true); - return c; - } return s; } diff --git a/src/inspect.cpp b/src/inspect.cpp index 7510b19da..4aeb82436 100644 --- a/src/inspect.cpp +++ b/src/inspect.cpp @@ -645,6 +645,9 @@ namespace Sass { } std::stringstream hexlet; + // dart sass compressed all colors in regular css always + // ruby sass and libsass does it only when not delayed + // since color math is going to be removed, this can go too bool compressed = opt.output_style == COMPRESSED; hexlet << '#' << std::setw(1) << std::setfill('0'); // create a short color hexlet if there is any need for it diff --git a/src/parser.cpp b/src/parser.cpp index 15b5cf9a1..1b7dac6ac 100644 --- a/src/parser.cpp +++ b/src/parser.cpp @@ -1578,7 +1578,7 @@ namespace Sass { return nr; } - Expression_Ptr Parser::lexed_hex_color(const ParserState& pstate, const std::string& parsed) + Value_Ptr Parser::lexed_hex_color(const ParserState& pstate, const std::string& parsed) { Color_Ptr color = NULL; if (parsed[0] != '#') { @@ -1628,6 +1628,19 @@ namespace Sass { return color; } + Value_Ptr Parser::color_or_string(const std::string& lexed) const + { + if (auto color = name_to_color(lexed)) { + auto c = SASS_MEMORY_NEW(Color, color); + c->is_delayed(true); + c->pstate(pstate); + c->disp(lexed); + return c; + } else { + return SASS_MEMORY_NEW(String_Constant, pstate, lexed); + } + } + // parse one value for a list Expression_Obj Parser::parse_value() { @@ -1670,7 +1683,7 @@ namespace Sass { { return SASS_MEMORY_NEW(Null, pstate); } if (lex< identifier >()) { - return SASS_MEMORY_NEW(String_Constant, pstate, lexed); + return color_or_string(lexed); } if (lex< percentage >()) @@ -1841,7 +1854,7 @@ namespace Sass { return schema->length() > 0 ? schema.detach() : NULL; } - String_Constant_Obj Parser::parse_static_value() + Value_Obj Parser::parse_static_value() { lex< static_value >(); Token str(lexed); @@ -1852,8 +1865,7 @@ namespace Sass { --str.end; --position; - String_Constant_Ptr str_node = SASS_MEMORY_NEW(String_Constant, pstate, str.time_wspace()); - return str_node; + return color_or_string(str.time_wspace());; } String_Obj Parser::parse_string() @@ -1986,7 +1998,7 @@ namespace Sass { } if (peek < exactly < '-' > >()) break; } - else if (lex< sequence < identifier > >()) { + else if (lex< identifier >()) { schema->append(SASS_MEMORY_NEW(String_Constant, pstate, lexed)); if ((*position == '"' || *position == '\'') || peek < alternatives < alpha > >()) { // need_space = true; diff --git a/src/parser.hpp b/src/parser.hpp index 31bac8dd7..e8f331f69 100644 --- a/src/parser.hpp +++ b/src/parser.hpp @@ -290,7 +290,7 @@ namespace Sass { String_Obj parse_url_function_argument(); String_Obj parse_interpolated_chunk(Token, bool constant = false, bool css = true); String_Obj parse_string(); - String_Constant_Obj parse_static_value(); + Value_Obj parse_static_value(); String_Schema_Obj parse_css_variable_value(bool top_level = true); String_Schema_Obj parse_css_variable_value_token(bool top_level = true); String_Obj parse_ie_property(); @@ -325,6 +325,8 @@ namespace Sass { Error_Obj parse_error(); Debug_Obj parse_debug(); + Value_Ptr color_or_string(const std::string& lexed) const; + // be more like ruby sass Expression_Obj lex_almost_any_value_token(); Expression_Obj lex_almost_any_value_chars(); @@ -380,12 +382,12 @@ namespace Sass { static Number_Ptr lexed_number(const ParserState& pstate, const std::string& parsed); static Number_Ptr lexed_dimension(const ParserState& pstate, const std::string& parsed); static Number_Ptr lexed_percentage(const ParserState& pstate, const std::string& parsed); - static Expression_Ptr lexed_hex_color(const ParserState& pstate, const std::string& parsed); + static Value_Ptr lexed_hex_color(const ParserState& pstate, const std::string& parsed); private: Number_Ptr lexed_number(const std::string& parsed) { return lexed_number(pstate, parsed); }; Number_Ptr lexed_dimension(const std::string& parsed) { return lexed_dimension(pstate, parsed); }; Number_Ptr lexed_percentage(const std::string& parsed) { return lexed_percentage(pstate, parsed); }; - Expression_Ptr lexed_hex_color(const std::string& parsed) { return lexed_hex_color(pstate, parsed); }; + Value_Ptr lexed_hex_color(const std::string& parsed) { return lexed_hex_color(pstate, parsed); }; static const char* re_attr_sensitive_close(const char* src); static const char* re_attr_insensitive_close(const char* src);