Skip to content

Commit

Permalink
Merge pull request #797 from xzyfer/fix/op-number-units
Browse files Browse the repository at this point in the history
Properly hydrate numbers after operations in variable assignments
  • Loading branch information
xzyfer committed Jan 3, 2015
2 parents 9087a77 + 8b399d1 commit 5045bce
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 8 deletions.
9 changes: 3 additions & 6 deletions eval.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -598,11 +598,8 @@ namespace Sass {
// behave according to as ruby sass (add leading zero)
if (value->concrete_type() == Expression::NUMBER) {
Number* n = static_cast<Number*>(value);
value = new (ctx.mem) Number(n->path(),
n->position(),
n->value(),
n->unit(),
true);
value = new (ctx.mem) Number(*n);
static_cast<Number*>(value)->zero(true);
}
else if (value->concrete_type() == Expression::STRING) {
String_Constant* s = static_cast<String_Constant*>(value);
Expand Down Expand Up @@ -953,7 +950,7 @@ namespace Sass {
string r_unit(tmp.unit());
if (l_unit != r_unit && !l_unit.empty() && !r_unit.empty() &&
(op == Binary_Expression::ADD || op == Binary_Expression::SUB)) {
error("cannot add or subtract numbers with incompatible units", l->path(), l->position());
error("Incompatible units: '"+r_unit+"' and '"+l_unit+"'.", l->path(), l->position());
}
Number* v = new (ctx.mem) Number(*l);
v->position(b->position());
Expand Down
8 changes: 6 additions & 2 deletions inspect.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -368,8 +368,12 @@ namespace Sass {
d.resize(d.length()-1);
}
if (d[d.length()-1] == '.') d.resize(d.length()-1);
if (n->numerator_units().size() > 1 || n->denominator_units().size() > 0) {
error(d + n->unit() + " is not a valid CSS value", n->path(), n->position());
if (n->numerator_units().size() > 1 ||
n->denominator_units().size() > 0 ||
(n->numerator_units().size() && n->numerator_units()[0].find_first_of('/') != string::npos) ||
(n->numerator_units().size() && n->numerator_units()[0].find_first_of('*') != string::npos)
) {
error(d + n->unit() + " isn't a valid CSS value.", n->path(), n->position());
}
if (!n->zero()) {
if (d.substr(0, 3) == "-0.") d.erase(1, 1);
Expand Down

0 comments on commit 5045bce

Please sign in to comment.