Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Fixing an edge case in which dimensions fetched from variables aren't…

… negated by the unary negation operator.
  • Loading branch information...
commit 135e02c271d5c8ee8c1fef4a4872e00c08410653 1 parent 21f0a95
@akhleung akhleung authored
Showing with 19 additions and 4 deletions.
  1. +18 −1 eval_apply.cpp
  2. +1 −3 node_factory.hpp
View
19 eval_apply.cpp
@@ -510,7 +510,24 @@ namespace Sass {
case Node::unary_minus: {
Node arg(eval(expr[0], prefix, env, f_env, new_Node, ctx, bt));
if (arg.is_numeric()) {
- result = new_Node(expr.path(), expr.line(), -arg.numeric_value());
+ double neg_val = -arg.numeric_value();
+ Node::Type t = arg.type();
+ switch (t)
+ {
+ case Node::number:
+ case Node::numeric_percentage: {
+ result = new_Node(expr.path(), expr.line(), neg_val, t);
+ } break;
+
+ case Node::numeric_dimension: {
+ result = new_Node(expr.path(), expr.line(), neg_val, arg.unit());
+ } break;
+
+ default: {
+ // unreachable
+ result = arg;
+ } break;
+ }
}
else {
result = new_Node(Node::unary_minus, expr.path(), expr.line(), 1);
View
4 node_factory.hpp
@@ -26,9 +26,7 @@ namespace Sass {
Node operator()(Node::Type type, string file, size_t line, Token t);
// for making boolean values or interior nodes that have children
Node operator()(Node::Type type, string file, size_t line, size_t size);
- // // for making nodes representing boolean values
- // Node operator()(Node::Type type, string file, size_t line, bool b);
- // for making nodes representing numbers
+ // for making nodes representing numbers and numeric percentages
Node operator()(string file, size_t line, double v, Node::Type type = Node::number);
// for making nodes representing numeric dimensions (e.g. 5px, 3em)
Node operator()(string file, size_t line, double v, const Token& t);
Please sign in to comment.
Something went wrong with that request. Please try again.