Skip to content

Commit

Permalink
@for with units; fixes #548
Browse files Browse the repository at this point in the history
  • Loading branch information
robocoder committed Feb 6, 2018
1 parent 593b929 commit d380170
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions src/Compiler.php
Expand Up @@ -1772,9 +1772,18 @@ protected function compileChild($child, OutputBlock $out)
list(, $for) = $child;

$start = $this->reduce($for->start, true);
$end = $this->reduce($for->end, true);

if ( ! ($start[2] == $end[2] || $end->unitless())) {
$this->throwError('Incompatible units: "%s" and "%s".', $start->unitStr(), $end->unitStr());

break;
}

$unit = $start[2];
$start = $start[1];
$end = $this->reduce($for->end, true);
$end = $end[1];
$end = $end[1];

$d = $start < $end ? 1 : -1;

for (;;) {
Expand All @@ -1784,7 +1793,7 @@ protected function compileChild($child, OutputBlock $out)
break;
}

$this->set($for->var, new Node\Number($start, ''));
$this->set($for->var, new Node\Number($start, $unit));
$start += $d;

$ret = $this->compileChildren($for->children, $out);
Expand Down

2 comments on commit d380170

@groovenectar
Copy link

@groovenectar groovenectar commented on d380170 Jun 20, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

EDIT: This commit does not appear to be the cause of this particular error. But it seems there is an issue with where it checks the units in min() and max()...

I think this might be causing the following error:

/* Incompatible units: &quot;px&quot; and &quot;&quot;.: line: 76 */

Here is the relevant SCSS:

$padding-value: max($padding - $outline-width, 0);

$padding - $outline-width ends up being a 'px' value. The error disappears if I change it to 0px.

Perhaps 0 should be a special case?

@robocoder
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@groovenectar good idea; I've fixed this in 3d3fd50

Please sign in to comment.