Skip to content
This repository has been archived by the owner on Dec 5, 2019. It is now read-only.

Error parsing CSS/Less: error evaluating function round math functions take numbers as parameters #353

Open
indreksiitan opened this issue Sep 21, 2017 · 7 comments

Comments

@indreksiitan
Copy link

indreksiitan commented Sep 21, 2017

Still trying to get Semantic UI to compile. Now getting the following error:
Error parsing CSS/Less: error evaluating function round math functions take numbers as parameters

Unfortunately my framework composes the Less source dynamically and then tries to compile so the reference given (index:10890) cannot easily be traced back to the exact Less source.

But the error is given in the _math() function in Functions.php, where the code is:

if ($args[0] instanceof Less_Tree_Dimension) {
    ....
} elseif (is_numeric($args[0])) {
    ....
} else {
    throw new Less_Exception_Compiler('math functions take numbers as parameters');
}

var_dumping $args[0] at that point shows:

[0]=>
object(Less_Tree_Operation)#102282 (5) {
  ["op"]=>
  string(1) "*"
  ["operands"]=>
  array(2) {
    [0]=>
    object(Less_Tree_Dimension)#102263 (4) {
      ["value"]=>
      float(1.285714285714286)
      ["unit"]=>
      object(Less_Tree_Unit)#102259 (5) {
        ["numerator"]=>
        array(0) {
        }
        ["denominator"]=>
        array(0) {
        }
        ["backupUnit"]=>
        NULL
        ["type"]=>
        string(4) "Unit"
        ["cache_string"]=>
        NULL
      }
      ["type"]=>
      string(9) "Dimension"
      ["cache_string"]=>
      NULL
    }
    [1]=>
    object(Less_Tree_Dimension)#130987 (4) {
      ["value"]=>
      float(14)
      ["unit"]=>
      object(Less_Tree_Unit)#130986 (5) {
        ["numerator"]=>
        array(1) {
          [0]=>
          string(2) "px"
        }
        ["denominator"]=>
        array(0) {
        }
        ["backupUnit"]=>
        NULL
        ["type"]=>
        string(4) "Unit"
        ["cache_string"]=>
        NULL
      }
      ["type"]=>
      string(9) "Dimension"
      ["cache_string"]=>
      NULL
    }
  }
  ["isSpaced"]=>
  bool(true)
  ["type"]=>
  string(9) "Operation"
  ["cache_string"]=>
  NULL
}

So it looks like having an expression inside round() is not handled.

Looking at Semantic source, this is probably the place where it fails:

/*
  This rounds @size values to the closest pixel then expresses that value in (r)em.
  This ensures all size values round to exact pixels
*/
@mini            : unit( round(@miniSize * @emSize) / @emSize, rem);
@tiny            : unit( round(@tinySize * @emSize) / @emSize, rem);
@small           : unit( round(@smallSize * @emSize) / @emSize, rem);
@medium          : unit( round(@mediumSize * @emSize) / @emSize, rem);
@large           : unit( round(@largeSize * @emSize) / @emSize, rem);
@big             : unit( round(@bigSize * @emSize) / @emSize, rem);
@huge            : unit( round(@hugeSize * @emSize) / @emSize, rem);
@massive         : unit( round(@massiveSize * @emSize) / @emSize, rem);

Is this something easily solvable?

@kylekatarnls
Copy link

kylekatarnls commented Sep 22, 2017

Hi, the following test succeed: https://github.com/kylekatarnls/less.php/blob/master/test/Fixtures/math/style.less

So I guess, @miniSize or @emSize is not numeric. Can you please dump the declarations of all size variables?

@kylekatarnls
Copy link

I tried with values there and get no failure: https://github.com/Semantic-Org/Semantic-UI/blob/master/src/themes/default/globals/site.variables

I will try later with the whole file, but this file may not the the cause.

@indreksiitan
Copy link
Author

Hey Kyle,

I posted you a link to a repeatable test case in Gitter private message. Let me know if you can get it from there or should I post it here publicly.

@indreksiitan
Copy link
Author

Kyle, have you had time to look at this?

@kylekatarnls
Copy link

Sorry @indreksiitan many project on the fire and I dropped less.php in favor of my own wrapper of the actual less node package. It requires to install node but allows to o use any version of less with no compatibility issue.

@indreksiitan
Copy link
Author

@kylekatarnls - dropping the whole Node.JS ecosystem into our framework really isn't a viable option. I've been trying to tackle this myself for multiple days now, but unfortunately to no success. Is there a way to contact you directly and maybe try to work out a consulting deal to get this fixed? At this moment I'm willing to pay to get this to work as migrating to other solutions are even more costly.

@kylekatarnls
Copy link

At the contrary, it's not dropping the node.js ecosystem. less.php is a pure PHP library while less is the native node.js less package just called by PHP.

Else you can reach me via: http://contact.selfbuild.fr/

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants