Skip to content

Commit

Permalink
Change leading zero fraction compression logic
Browse files Browse the repository at this point in the history
  • Loading branch information
mgreter committed Jan 9, 2016
1 parent 9319f6e commit 7ea7f1f
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 8 deletions.
2 changes: 1 addition & 1 deletion src/ast.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2247,7 +2247,7 @@ namespace Sass {
// check if handling negative nr
size_t off = res[0] == '-' ? 1 : 0;
// remove leading zero from floating point in compressed mode
if (res[off] == '0' && res[off+1] == '.') res.erase(off, 1);
if (zero() && res[off] == '0' && res[off+1] == '.') res.erase(off, 1);
}

// add unit now
Expand Down
19 changes: 13 additions & 6 deletions src/eval.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -921,13 +921,16 @@ if (op_type == Sass_OP::SUB) interpolant = false;
Backtrace here(backtrace(), c->pstate(), ", in function `" + c->name() + "`");
exp.backtrace_stack.push_back(&here);
// if it's user-defined, eval the body
if (body) result = body->perform(this);
if (body) {

result = body->perform(this);
}
// if it's native, invoke the underlying CPP function
else {
Sass_Output_Style style = ctx.c_options->output_style;
ctx.c_options->output_style = SASS_STYLE_COMPACT;
// ctx.c_options->output_style = SASS_STYLE_COMPACT;
result = func(fn_env, *env, ctx, def->signature(), c->pstate(), backtrace());
ctx.c_options->output_style = style;
// ctx.c_options->output_style = style;
}
if (!result) error(std::string("Function ") + c->name() + " did not return a value", c->pstate());
exp.backtrace_stack.pop_back();
Expand Down Expand Up @@ -1049,8 +1052,12 @@ if (op_type == Sass_OP::SUB) interpolant = false;
{
using Prelexer::number;
Expression* result = 0;
bool zero = !( t->value().substr(0, 1) == "." ||
t->value().substr(0, 2) == "-." );
size_t L = t->value().length();
bool zero = !( (L > 0 && t->value().substr(0, 1) == ".") ||
(L > 1 && t->value().substr(0, 2) == "0.") ||
(L > 1 && t->value().substr(0, 2) == "-.") ||
(L > 2 && t->value().substr(0, 3) == "-0.")
);

const std::string& text = t->value();
size_t num_pos = text.find_first_not_of(" \n\r\t");
Expand All @@ -1073,7 +1080,7 @@ if (op_type == Sass_OP::SUB) interpolant = false;
t->pstate(),
sass_atof(num.c_str()),
"%",
zero);
true);
break;
case Textual::DIMENSION:
result = SASS_MEMORY_NEW(ctx.mem, Number,
Expand Down
2 changes: 1 addition & 1 deletion src/parser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1414,7 +1414,7 @@ namespace Sass {

// also handle the 10em- foo special case
// alternatives < exactly < '.' >, .. > -- `1.5em-.75em` is split into a list, not a binary expression
if (lex< sequence< dimension, optional< sequence< exactly<'-'>, lookahead< alternatives < exactly < '.' >, space > > > > > >())
if (lex< sequence< dimension, optional< sequence< exactly<'-'>, lookahead< alternatives < space > > > > > >())
{ return SASS_MEMORY_NEW(ctx.mem, Textual, pstate, Textual::DIMENSION, lexed); }

if (lex< sequence< static_component, one_plus< strict_identifier > > >())
Expand Down

0 comments on commit 7ea7f1f

Please sign in to comment.