Page MenuHomePhabricator

Unexpected compilation clamp() with mixed units
Closed, ResolvedPublic

Description

Tu Nguyen @mrtuvn@github.com wrote on 13 May 2022 at https://github.com/wikimedia/less.php/issues/78:
error evaluating function `clamp`
PHP Notice: Object of class Less_Tree_Dimension could not be converted to int
in /var/www/html/vendor/wikimedia/less.php/lib/Less/Functions.php on line 33

https://developer.mozilla.org/en-US/docs/Web/CSS/clamp

jamie-selesti wrote on 11 Oct 2022:

Same here, we use this library as its bundled with Magento's official framework

Gappa wrote on 28 Nov 2022:

One way to get it working is to escape the whole function:

  • property: ~"clamp(10px, 5vw, 100px)";
  • property: ~"clamp(var(--css-variable), 5vw, 100px)";
  • property: ~"clamp(@{lessVariable}, 5vw, 100px)";

Event Timeline

I supected that this was due to upstream only supporting it after Less.js 2.5.3, but looks like it does work correctly upstream on our current reference version:

http://lesscss.org/less-preview/#eyJjb2RlIjoieCB7XG4gIHdpZHRoOiBjbGFtcCgxMHB4LCA1dncsIDEwMHB4KTtcbn0iLCJhY3RpdmVWZXJzaW9uIjoiMi41LjMifQ==

Thus confirming as bug rather than feature request. (I know it feels like a bug either way, but less.php aims to offer parity with less.js, so matching behaviour would be expected.)

Krinkle triaged this task as Medium priority.

Change #1025474 had a related patch set uploaded (by Krinkle; author: Krinkle):

[mediawiki/libs/less.php@master] Less_Functions: Avoid clobbering `clamp()` with internal helper

https://gerrit.wikimedia.org/r/1025474

Change #1025474 merged by jenkins-bot:

[mediawiki/libs/less.php@master] Less_Functions: Avoid clobbering `clamp()` with internal helper

https://gerrit.wikimedia.org/r/1025474