Skip to content

Commit 135e02c

Browse files
author
Aaron Leung
committed
Fixing an edge case in which dimensions fetched from variables aren't negated by the unary negation operator.
1 parent 21f0a95 commit 135e02c

File tree

2 files changed

+19
-4
lines changed

2 files changed

+19
-4
lines changed

eval_apply.cpp

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -510,7 +510,24 @@ namespace Sass {
510510
case Node::unary_minus: {
511511
Node arg(eval(expr[0], prefix, env, f_env, new_Node, ctx, bt));
512512
if (arg.is_numeric()) {
513-
result = new_Node(expr.path(), expr.line(), -arg.numeric_value());
513+
double neg_val = -arg.numeric_value();
514+
Node::Type t = arg.type();
515+
switch (t)
516+
{
517+
case Node::number:
518+
case Node::numeric_percentage: {
519+
result = new_Node(expr.path(), expr.line(), neg_val, t);
520+
} break;
521+
522+
case Node::numeric_dimension: {
523+
result = new_Node(expr.path(), expr.line(), neg_val, arg.unit());
524+
} break;
525+
526+
default: {
527+
// unreachable
528+
result = arg;
529+
} break;
530+
}
514531
}
515532
else {
516533
result = new_Node(Node::unary_minus, expr.path(), expr.line(), 1);

node_factory.hpp

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,7 @@ namespace Sass {
2626
Node operator()(Node::Type type, string file, size_t line, Token t);
2727
// for making boolean values or interior nodes that have children
2828
Node operator()(Node::Type type, string file, size_t line, size_t size);
29-
// // for making nodes representing boolean values
30-
// Node operator()(Node::Type type, string file, size_t line, bool b);
31-
// for making nodes representing numbers
29+
// for making nodes representing numbers and numeric percentages
3230
Node operator()(string file, size_t line, double v, Node::Type type = Node::number);
3331
// for making nodes representing numeric dimensions (e.g. 5px, 3em)
3432
Node operator()(string file, size_t line, double v, const Token& t);

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy