Giter Club home page Giter Club logo

less.php's Introduction

Packagist

Less.php

This is a PHP port of the official LESS processor.

About

The code structure of Less.php mirrors that of upstream Less.js to ensure compatibility and help reduce maintenance. The port is currently compatible with Less.js 2.5.3. Please note that "inline JavaScript expressions" (via eval or backticks) are not supported.

Installation

You can install the library with Composer or standalone.

If you have Composer installed:

  1. Run composer require wikimedia/less.php
  2. Use Less_Parser in your code.

Or standalone:

  1. Download Less.php and upload the PHP files to your server.
  2. Include the library:
    require_once '[path to]/less.php/lib/Less/Autoloader.php';
    Less_Autoloader::register();
  3. Use Less_Parser in your code.

Security

The LESS processor language is powerful and includes features that may read or embed arbitrary files that the web server has access to, and features that may be computationally exensive if misused.

In general you should treat LESS files as being in the same trust domain as other server-side executables, such as PHP code. In particular, it is not recommended to allow people that use your web service to provide arbitrary LESS code for server-side processing.

See also SECURITY.

Who uses Less.php?

Integrations

Less.php has been integrated with various other projects.

Transitioning from Leafo/lessphp

If you're looking to transition from the Leafo/lessphp library, use the lessc.inc.php adapter file that comes with Less.php.

This allows Less.php to be a drop-in replacement for Leafo/lessphp.

Download Less.php, unzip the files into your project, and include its lessc.inc.php instead.

Note: The setPreserveComments option is ignored. Less.php already preserves CSS block comments by default, and removes LESS inline comments.

Drupal

Less.php can be used with Drupal's less module via the lessc.inc.php adapter. Download Less.php and unzip it so that lessc.inc.php is located at sites/all/libraries/lessphp/lessc.inc.php, then install the Drupal less module as usual.

WordPress

  • wp_enqueue_less is a Composer package for use in WordPress themes and plugins. It provides a wp_enqueue_less() function to automatically manage caching and compilation on-demand, and loads the compressed CSS on the page.
  • JBST framework bundles a copy of Less.php.
  • The lessphp plugin bundles a copy of Less.php for use in other plugins or themes. This dependency can also be combined with the TGM Library.

Credits

Less.php was originally ported to PHP in 2011 by Matt Agar and then updated by Martin Jantošovič in 2012. From 2013 to 2017, Josh Schmidt lead development of the library. Since 2019, the library is maintained by Wikimedia Foundation.

Contribute

less.php's People

Contributors

adrianbadarau avatar agar avatar asenar avatar bertmert avatar catrope avatar dannys712 avatar dkrnl avatar fabrizim avatar jdforrester avatar krinkle avatar lduer avatar maxsem avatar mlocati avatar mordred avatar nodge avatar nyordanov avatar oyejorge avatar pafnuty avatar paladox avatar phrozenbyte avatar polishdeveloper avatar ravisorg avatar reedy avatar rummik avatar s7eph4n avatar storeman avatar thiemowmde avatar umherirrender avatar vburlak avatar zghosts avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

less.php's Issues

Fix and make a release that works on PHP 8.0

Under PHP v8.0.0
Deprecated: Required parameter $rules follows optional parameter $value in K:\UwAmp\www\exp2\external\less.php\lib\Less\Tree\Directive.php on line 20

Currently
public function __construct($name, $value = null, $rules, $index = null, $currentFileInfo = null, $debugInfo = null ){

Possible fix
public function __construct($name = null, $value = null, $rules = null, $index = null, $currentFileInfo = null, $debugInfo = null ){

Is 2.0 still supported?

We're currently using a 1.x version in our open source application and would like to update. However, the PHP version dependency in v3.0 is too high for our community. We are considering using v2.0 but I noticed that it was released in February and v3.0 was released just a month later. Since then no updates have been provided for v2.0.

Is v2.0 a safe version to go with? Is there anything we should be aware of in terms of long-term maintenance?

Thanks!

Tree_Javascript or Tree_JavaScript?

I included lessphp to one of my projects and my automatic syntax checker complained about lib/Less/Tree/JavaScript.php not to exist.

Taking a closer look there is Less_Tree_Javascript used in the class itself and in Parser.php, but Less_Tree_JavaScript in Functions.php and Tree/Quoted.php.

Not a big issue, but either of these should be corrected.

Single and double quote are treated as different identifiers

Single and double quote are treated as different identifiers. This is contrast to javascript based LESS that treats a quoted identifier as a quoted identifier regardless of whether the quotes were single or double. It can cause a little confusion.

As an example:

.test-mixin(@value) when (@value = "test") {
  background: red;
}

.test-mixin(@value) when (@value = 'test') {
  background: blue;
}

double {
  .test-mixin("test")
}
single {
  .test-mixin('test')
}

Using wikimedia/less.php this compiles to the following:

double {
  background: red;
}
single {
  background: blue;
}

However, using lessc Node module you get:

double {
  background: red;
  background: blue;
}
single {
  background: red;
  background: blue;
}

Using versions:

$ lessc --version
lessc 4.1.2 (Less Compiler) [JavaScript]
$ ./vendor/bin/lessc --version
lessc 3.1.0 (less.php)

seperate sourcemaps are badly generated

Hello guys, this is my first use of less.php, so here is my exemple:
The web DocumentRoot is public_html/ , which includes these files :

  • less_php/
    • vendor/
    • composer.json
    • composer.lock
    • theme.less
    • footer.less
    • header.less
    • components/
      • buttons.less
    • index.php

index.php

<?php
require __DIR__ . '/vendor/autoload.php';

$less_file = __DIR__ . '/theme.less';

$options = array(
	'sourceMap'			=> true,
	'sourceMapWriteTo'	=> __DIR__ . '/theme.map',
	'sourceMapURL'		=> '/less_php/theme.map',
	);
$parser = new Less_Parser($options);
$parser->parseFile( $less_file , 'http://exemple.com/less_php/' );
$generated_css = $parser->getCss();

$css_file = fopen("theme.css", "w") or die("Unable to open theme.css!");
fwrite($css_file, $generated_css);
fclose($css_file);
?>

<!DOCTYPE html>
<html>
<head>
	<link rel="stylesheet" type="text/css" href="theme.css">
</head>
    <body>

	<div class="h1">Body .h1</div>

	<div class="btn">bouton</div>

	<footer>
		<div class="h2">footer .h2</div>
	</footer>

    </body>
</html>

theme.less

@primary-color: #990000;
@primary-font-siz: 1.8rem;

div {
  background: url('test.jpeg');
}

@import 'header';

@import 'components/buttons';

@import 'footer';

footer.less

footer {
  .h2 {
    color: @primary-color;
    font-size: @primary-font-siz;
  }
}

header.less

body {
  .h1 {
    color: @primary-color;
    font-size: @primary-font-siz;
  }
}

components/buttons.less

.btn {
  background-color: @primary-color;
  font-size: @primary-font-siz;
}

The generated theme.css

div {
  background: url('http://exemple.com/less_php/test.jpeg');
}
body .h1 {
  color: #990000;
  font-size: 1.8rem;
}
.btn {
  background-color: #990000;
  font-size: 1.8rem;
}
footer .h2 {
  color: #990000;
  font-size: 1.8rem;
}
/*# sourceMappingURL=/less_php/theme.map */

The issue

the generated theme.map looks like this

{
   "version":3,
   "sources":[
      "home\/foo\/public_html\/less_php\/theme.less",
      "home\/foo\/public_html\/less_php\/header.less",
      "home\/foo\/public_html\/less_php\/components\/buttons.less",
      "home\/foo\/public_html\/less_php\/footer.less"
   ],
   "names":[],
   "mappings":"AAGA;EACE,gBAAgB,wCAAhB;;ACHF,IACE;EACE,cAAA;EACA,iBAAA;;ACJJ;EACE,yBAAA;EACA,iBAAA;;ACDF,MACE;EACE,cAAA;EACA,iBAAA"
}

The "sources" values shouldn't be absolute, because when using the navigator inspector, the navigator can't access to them.

The fix

vendor/wikimedia/less.php/lib/Less/SourceMap/Generator.php
I removed this block :

if(strpos($filename, '\\') === 0 || strpos($filename, '/') === 0){
    $filename = substr($filename, 1);
}

And I changed this line :

$this->sources[$fileInfo['currentUri']] = $fileInfo['filename'];

to become :

$this->sources[$fileInfo['currentUri']] = $fileInfo['currentUri'];

So the result of the new generated theme.map is :

{
   "version":3,
   "sources":[
      "http:\/\/exemple.com\/less_php\/theme.less",
      "http:\/\/exemple.com\/less_php\/header.less",
      "http:\/\/exemple.com\/less_php\/components\/buttons.less",
      "http:\/\/exemple.com\/less_php\/footer.less"
   ],
   "names":[],
   "mappings":"AAGA;EACE,gBAAgB,wCAAhB;;ACHF,IACE;EACE,cAAA;EACA,iBAAA;;ACJJ;EACE,yBAAA;EACA,iBAAA;;ACDF,MACE;EACE,cAAA;EACA,iBAAA"
}

And everything is ok in the navigator inspector 💯

Thank you for your help and suggestions 👍

ID reference prefixed

Entering this in a less file:
clip-path: ~"url(#myClip)";
Results in:

clip-path: url(https://example.com/wp-content/themes/theme/assets/css/#myClip);
It is interpreting the ID reference as a file, which it isn't.
Can this be fixed/changed please?

Undefined array key "currentUri" in [...]Mapped.php Line 68 when using @import (inline)

I use (at)import (inline) to read the contents of a css file containing my container queries (since they are not yet supportet).
This worked fine up to version 4.2.1.
In Version 4.3.0 it breaks with "Undefined array key "currentUri" in [...]Mapped.php Line 68"

The reason is that in Import.php, Line 179 the empty array for $currentFileInfo has been replaced by one containing two keys, but not the "currentUri" key, leading to the mentioned error in Mapped.php, where this key is read without checking its existence. The only check here is if the array is not falsy.

Deprecation notices on php 8.1

When running phpunit tests with php 8.1, Implicit conversion from float to int loses precision deprecation notices are thrown.

We can fix this to add support for php 8.1

Add previous context to re-thrown LESS_Exceptions*

Example: when a custom less functions throws, less.php will catch this exception and throw a new Less_Exception_Compiler, without passing the originating exception (which would be very helpful for tracking down the error).

See Less_Tree_Call::compile():

try {
	$func = new Less_Functions($env, $this->currentFileInfo);
	$result = call_user_func_array( array($func,$nameLC),$args);
} catch (Exception $e) {
	throw new Less_Exception_Compiler('error evaluating function `' . $this->name . '` '.$e->getMessage().' index: '. $this->index);
}

An easy fix would be pass the originating exception as $previous to constructor of Less_Exception_Compiler:

	throw new Less_Exception_Compiler('error evaluating function `' . $this->name . '` '.$e->getMessage().' index: '. $this->index, $e );

Error in Compiling

This is not compiling

@width: 960px;
.nav {
  width: @width / 3;
  color: #001 + #abc;
}
.body {
  width: 2 * @width / 3;
  font-family: "hel" + "vetica";
}

it give me this error

fatal error: ParseError: Unexpected input in anonymous-file-0.less on line 8, column 16
.body {
  width: 2 * @width / 3;
  font-family: \"hel\" + \"vetica\";
}

also getting here in this

.clearfix {
  display: block;
  zoom: 1;

  &:after {
    content: " ";
    display: block;
    font-size: 0;
    height: 0;
    clear: both;
    visibility: hidden;
  }
}

this is the error I get

fatal error: ParseError: Unexpected input in anonymous-file-0.less on line 6, column 14 
   &:after {
     content: \" \";
     display: block;
     font-size: 0;
     height: 0;

this is how I used php

try {
    $parser = new Less_Parser();
    $parser->parse($lessCode);
    return $parser->getCss();
  } catch (exception $e) {
    return "fatal error: " . $e->getMessage();
}

Import from google font

Thank you for building this great project.

I have this in my source.less.

@import url('https://fonts.googleapis.com/css?family=Open+Sans:300,300i,400,400i,600,600i,700,700i');

I would expect it would compile to

/* cyrillic-ext */
@font-face {
  font-family: 'Open Sans';
  font-style: italic;
  font-weight: 300;
  font-stretch: 100%;
  src: url(https://fonts.gstatic.com/s/opensans/v34/memtYaGs126MiZpBA-UFUIcVXSCEkx2cmqvXlWqWtE6F15M.woff2) format('woff2');
  unicode-range: U+0460-052F, U+1C80-1C88, U+20B4, U+2DE0-2DFF, U+A640-A69F, U+FE2E-FE2F;
}
....

But it does not happen.

Or is this not possible?

Allowed memory limit exceeded when unserializing cache.

php 8.2.14, fpm-fcgi, Apache/2.4.58 (Fedora Linux) OpenSSL/3.1.1

I am getting the error:
wikimedia/less.php/lib/Less/Parser.php:612 Allowed memory size of 134217728 bytes exhausted (tried to allocate 20480 bytes)

The line in question is:

$cache = unserialize( file_get_contents( $cache_file ) );

For some reason it doesn't like unserializing some rules cached by

file_put_contents( $cache_file, serialize( $rules ) );

I have manually cleared out the cache files and tried again, resulting in the same issue. I have also updated to current (today) less.php code from GitHub.

I have not been able to track down the specific cached rules that result in the issue. I have a gut feeling it could be a cumulative memory leak rather than any specific rule, though no hard evidence to back that up.

For now, I have disabled reading the less parser cache (by hacking line 607 to 0 && file_exists) and everything works, albeit without the benefits of the cache.

The same .less source compiled under php8.1. But now results in the above under php8.2 (though there are some other environment differences, so php version may be a completely spurious clue).

Escaped calc inside Recursive Mixins

I use version 2.5.3 off less and test it with this compiler: http://ecomfe.github.io/est/fiddle/#version=2.5.3&autoprefix=false

In this version the calc is pretty strict and throws all my units all over the place, so I escape it like this:
width: calc(100vw - 30px); becomes this: width: calc(~"100vw - 30px");
It is working, but in combination with Recursive Mixins it gives me errors.

My code:

        .generate_rows_tablet_m_4 (@i , @n) when (@i < 41) {
            .start-row-m-@{i}.row-m-4 {
                height: calc(~"100vw - 15px") !important;
                top: calc(@n * (~"50vw - 7.5px")) !important;
            }

            .generate_rows_tablet_m_4(@i + 1, @i * 0.5)
        }

        .generate_rows_tablet_m_4(2, 0.5);

The compiler tells me that a ) is missing in line 4.
When I remove the escape ~" " the error is gone and it compiles. Although my calculation is then wrong.

How can I fix this? I still want to use the "correct" calculation.

Support each() function (Less.js 3.7.0)

I am having a lot of trouble trying to upgrade FontAwesome to the latest version.

I’ve uploaded all the kit for FontAwesome 6 but running the compiler returns errors because of ParseError: Unexpected input in from the FontAwesome less files even though I believe they are syntatically correct (example below).

ParseError: Unexpected input in _sizing.less on line 15, column 5
13|
14| // step-based scale (with alignment)
15| each(.fa-sizes(), {
16|   .@{fa-css-prefix}-@{key} {
17|     .fa-size(@value);
18|   }

PHP v5.6-7.0 deprecation

Might want to note in the changes that less.php v3.2.0 is no longer compatible with PHP v5.6 nor v7.0. This is due to use of ?? as Null coalescing operator, and visibility options for const properties.

Uncaught Less Exception after moving from Leafo

I installed this version of the Less.php but I'm still getting errors like the following:

Uncaught Less_Exception_Chunk: ParseError: Unexpected input in functions.less on line 76, column 13
74| font-size:@min_font + px;
75| @media(min-width: @min_vw + px){
76| font-size:~'calc(' + @min_font + 'px + (' + @max_font + ' - ' + @min_font + ') * ((100vw - ' + @min_vw + 'px) / (' + @max_vw + ' - ' + @min_vw + ')))';
77| }
78| @media(min-width: @max_vw + px){
79| font-size: @max_font + px;
in...

Is there a set of rules of what needs to be changed in code that worked with leafo, upon migration to this version?

Strings used as selectors do not recognize parent selector

@disabled-selector: ~"&:disabled, &.disabled, &[disabled], .elementor-element.disabled& ";

button {
@{disabled-selector}
{
background: red;
}
}

yields:
button &:disabled, &.disabled, &[disabled], .elementor-element.disabled&
{
background: red;
}

PHP notice "Undefined property: Less_Tree_Variable::$value" for files imported through variables

When a file is imported, and the filename is specified through a less variable, a PHP notice is issued:

PHP Notice:  Undefined property: Less_Tree_Variable::$value
  in [...]/Less/Tree/Import.php on line 108

The code line in question is:

} else if ($this->path instanceof Less_Tree_URL) {
	$path = $this->path->value->value;
}else{

Still, the import works.

Test case: import-notice-test-case.zip

This might be related to #27 also dealing with imports.

Improve "Operation on an invalid type" error with source line

This library needs to provide a little more feedback on this fatal compilation error: "Operation on an invalid type."
I'm thinking what .less file and which line.

The .less files I have, they compile nicely with less-plugin-clean-css for Node.js. But give this error with less.php.

To determine why it does not compile with less.php we need at least a hint.

Reference:
https://github.com/wikimedia/less.php/search?q=Operation+on+an+invalid+type

Deprecation warning in PHP 8.2

In PHP 8.2, we get the following warning

Warning: Undefined property: Less_Tree_Call::$unit in \lessphp\vendor\wikimedia\less.php\lib\Less\Tree\Dimension.php on line 85

When will it be fixed?

Parent selector "&" symbol not treated when in a :not() pseudo-class

Hi,
current selector in pseudo class selector :not() isn't treated :

.foo { 
    width: 100px;

    &-bar {
        background: blue;
    }
            
    &:not(&-bar) {
        background: green;
    }
}

Outputs :

.foo {
    width: 100px;
}
.foo-bar {
    background: blue;
}
.foo:not(&-bar) {
    background: green;
}

But it must be returned :

.foo {
    width: 100px;
}
.foo-bar {
    background: blue;
}
.foo:not(.foo-bar) {
    background: green;
}

It would be nice, if css variables will pass as is

code:

$parser = new \Less_Parser(['compress' => false, 'strictMath' => false]);
$parser->parse("
	:root {
	  --css-variable: 1;
	}
	.a {
	  animation-iteration-count: calc(var(--css-variable) * 2);
	}			
");

thrown exception:

Operation on an invalid type

Imported files get optimized incorrectly

Create the following 2 files

  1. test.less:
@media screen {
    body:not( .skin--responsive ) {
        @import 'test-import.less';
    }

    body.skin--responsive {
        @media ( min-width: 551px ) {
            @import 'test-import.less';
        }
    }
}
  1. test-import.less:
a {
    color: red;
}

Run

<?php
require_once 'lib/Less/Autoloader.php';
Less_Autoloader::register();
$parser = new Less_Parser();
$parser->parseFile( 'test.less' );
$css = $parser->getCss();
echo $css;

Expected:

The LESS compiler should produce:

@media screen {
  body:not( .skin--responsive ) a {
    color: red;
  }
}
@media screen and (min-width: 551px) {
  body.skin--responsive a {
    color: red;
  }
}

Actual:

@media screen {
  body:not( .skin--responsive ) a {
    color: red;
  }
}

Bug in README.md

The README file recommends a manual installation method:

Manually From Release
Step 1. Download the latest release and upload the PHP files to your server.
Step 2. Include the library:
require_once '[path to less.php]/Less.php';

However, there is no file named Less.php in the release zip https://github.com/wikimedia/less.php/archive/v2.0.0.zip . There is a file named Less.php.combine instead, but files are not concatenated with https://github.com/oyejorge/phpEasyMin .

The autoload method works.

@container queries support?

Hello, would be possilbe to add support for @container queries like:

@container (max-width: 650px) { ... }

Right now it throws: Fatal error: Uncaught Less_Exception_Chunk: ParseError: Unexpected input

Support CSS4 space-separated syntax for rgba() function (Less.js 3.8.1)

Hi there, we're currently using less/php v3.1.0 and are seeing errors when trying to import standard CSS files into our pipeline that use the newer syntax for rgba such as:

.test {
  color: rgba(0 0 0 0 / 89%);
}

Is there a plan to support this in a future version, as I see it's supported in Less.js? Thanks!

Embrace our fork

Upstream has archived their repo and points to ours as the recommmended path forward (https://github.com/oyejorge/less.php).

Let's therefore set our repo up properly:

  • Update or remove descriptions and websites references in code, documentation and other meta data that refer to upstream since those are now stale.
  • Convert the repo to use follow Wikimedia's boilerplate for libraries.
    • Latest PHPCS Codesniffer as used by MW.
    • Latest PHPUnit.
    • Add Phan and make pass.
  • Set up a mirror in Gerrit or move the repo to Gerrit so as to not be dependent on GitHub for our production source code.
  • Set up a Doxygen pipeline in WMF CI (or somehow with Travis commiting to a gh-pages branch, to a subdirectory based on the release tag and branch), and ensure all useful information from the upstream website is preserved in a set of docs/ Markdown pages rendered on the site.

See https://www.mediawiki.org/wiki/Manual:Developing_libraries.

Compiler doesn't import some remote CSS files

Steps to reproduce (*)

  1. On a .less file, import the following URL: @import url("https://fonts.googleapis.com/icon?family=Material+Icons");
  2. Compile LESS

Expected result (*)

  • Font is imported correctly

Actual result (*)

  • We get this error: File https://fonts.googleapis.com/icon not found

Root cause

We originally found this issue in Magento 2: magento/magento2#25119

We were able to track down the issue down to the less.php library. This URL doesn't work because it doesn't have the "css" word in it, which the library takes into account when importing css files: https://github.com/wikimedia/less.php/blob/master/lib/Less/Tree/Import.php#L44

Block comments in @font-face are moved to bottom of selector

Less_Tree_Ruleset is moving comments from their true position to the bottom of the selector. Consider the following CSS:

& when (@media-common = true) {
@font-face {
font-weight: @_weight_normal; /* This is a comment */
font-style: normal; /* Another Comment */
}
}

After parsing, this becomes:

& when (@media-common = true) {
@font-face {
font-weight: @_weight_normal;
font-style: normal;
/* This is a comment */
/* Another Comment */
}
}

This breaks out internal systems which uses block comments to denote critical CSS. Rules are then extracted as part of our post processing routine into critical and non-critical CSS.

The following line causes this:

( $this->root && $rule instanceof Less_Tree_Comment ) ||

Commenting out this line fixes the issue so that comments are placed correctly.

ParseError with variable interpolation after ':' in selector

This succeeds:

(new Less_Parser())->parse('@position: after; .@{position} {}');

This, however, fails:

(new Less_Parser())->parse('@position: after; &:@{position} {}');
ParseError: Unexpected input in anonymous-file-2.less on line 1, column 14
1| @foo: after; &:@{foo} {}

Both Less.js and lessphp compile it just fine. (cmp.)

Regression: CSS output differs from Less.js for mixin selector

Version: 4.2.0+

Description

A CSS class used as a mixin that has an extra definition with an attribute selector will cause all properties to be merged at the point of use of the mixin. See example below.
This behavior is unexpected and is different from the JS version.
In version 4.1.1, the behaviour was correct.

Source LESS code

.btn {
   color: blue;
   font-weight: bold;

   &[title] {
      background: lightgreen;
   }
}
.btn[disabled] {
   cursor: not-allowed;
   color: red;
}
.btn[test] {
   background-color: pink;
}

.btn-specific {
   .btn();
}

Current CSS output (version 4.2.0+)

.btn {
   color: blue;
   font-weight: bold;
} 
.btn[title] {
   background: lightgreen;
} 
.btn[disabled] {
   cursor: not-allowed;
   color: red;
} 
.btn[test] {
   background-color: pink;
} 
.btn-specific {
   color: blue;
   font-weight: bold;
   cursor: not-allowed;
   color: red;
   background-color: pink;
} 
.btn-specific[title] {
   background: lightgreen;
}

Expected CSS output

.btn {
   color: blue;
   font-weight: bold;
} 
.btn[title] {
   background: lightgreen;
} 
.btn[disabled] {
   cursor: not-allowed;
   color: red;
} 
.btn[test] {
   background-color: pink;
} 
.btn-specific {
   color: blue;
   font-weight: bold;
}
.btn-specific[title] {
   background: lightgreen;
}

Regression in v4.2.0

Hi there

I'm currently working on trying to upgrade this library from v3 to v4 in the Magento2 codebase. Because when working on local and when using grunt, Magento uses less.js. But in production deploys, Magento uses less.php (it's been like this for years, probably to avoid node.js requirements for the people/servers only having php available).

Magento had this problem for many years that less compilation in developer mode resulted in slightly different css output than in production mode, which is sometimes kind of annoying (example), but it's not as bad as it sounds.
So I really appreciate all the recent efforts in trying to port functionalities from less.js to less.php!

However, when trying out version 4.2.0, I'm getting compilation problems that didn't happen in 4.1.1, so I have the feeling there is a regression here somehow.
Error in Magento:

$ bin/magento setup:static-content:deploy -f en_US
Deploy using quick strategy
frontend/Magento/blank/en_US            61/2069             >--------------------------- 2%     1 sec
Compilation from source: app/design/frontend/Magento/blank/web/css/styles-m.less
variable @fontValue is undefined in file var/view_preprocessed/pub/static/frontend/Magento/blank/en_US/css/source/lib/_typography.less in _typography.less on line 235, column 34
233|         & {
234|             .lib-font-size-value(@_p-margin-top);
235|             .lib-css(margin-top, @fontValue);
236|         }
237|
238|         & { in _typography.less in _resets.less in _reset.less

I've performed a git bisect on this package and found out that the problem got introduced in 6d652ed

The less compilation in Magento is quite complex and involves a whole bunch of different less files, so sorry for not (yet) providing a minimal reproducible example of how to trigger the problem, I simply lack the time at the moment.

Fix various warnings from PHPStan analysis

I ran the software PHPStan (https://github.com/phpstan/phpstan) with level 0 and got some errors. Here is the output:

------ ------------------------------------------------------------------- 
  Line   libs/less.php/Exception/Parser.php                                 
 ------ ------------------------------------------------------------------- 
  42     Access to an undefined property Less_Exception_Parser::$previous.  
 ------ ------------------------------------------------------------------- 

 ------ ----------------------------------------------------------------------------------------------------- 
  Line   libs/less.php/Parser.php                                                                             
 ------ ----------------------------------------------------------------------------------------------------- 
  111    Class Less_Environment does not have a constructor and must be instantiated without any parameters.  
 ------ ----------------------------------------------------------------------------------------------------- 

 ------ ---------------------------------------------------------------------------------------------- 
  Line   libs/less.php/Tree.php                                                                        
 ------ ---------------------------------------------------------------------------------------------- 
  83     Class Less_Tree does not have a constructor and must be instantiated without any parameters.  
 ------ ---------------------------------------------------------------------------------------------- 

 ------ ---------------------------------------------------------------------------------- 
  Line   libs/less.php/Tree/Quoted.php                                                     
 ------ ---------------------------------------------------------------------------------- 
  48     Class Less_Tree_Javascript referenced with incorrect case: Less_Tree_JavaScript.  
 ------ ---------------------------------------------------------------------------------- 

 ------ -------------------------------------------------------------------- 
  Line   libs/less.php/Tree/Url.php                                          
 ------ -------------------------------------------------------------------- 
  73     Class Less_Tree_Url referenced with incorrect case: Less_Tree_URL.  
 ------ -------------------------------------------------------------------- 

ParseError when using each() function

Simple functions such as

@selectors: blue, green, red;

each(@selectors, {
  .sel-@{value} {
    a: b;
  }
});

currently throw

Fatal error: Uncaught Less_Exception_Chunk: ParseError: Unexpected input in anonymous-file-0.less on line 3, column 5
1| @selectors: blue, green, red;
2|
3| each(@selectors, {
4|   .sel-@{value} {
5|     a: b;
 in ~\lib\Less\Parser.php:677

Source code question. Cache::get() what are list files for?

Source code question. What are $list_files for?
It is possible to calculate $compiled_name from $less_files and check its presence. What is the file list for?

I want to reduce disk access.
If these lists are really needed, then make friends with memcached through cache_method

PHP 8.2 Creation of dynamic property warning

Hello,
With PHP 8.2 getting creation of dynamic property warnings on compile:

PHP Deprecated: Creation of dynamic property Less_Tree_Variable::$parensInOp is deprecated in [.../less.php/lib/Less/Parser.php:2463]
PHP Deprecated: Creation of dynamic property Less_Tree_Dimension::$parensInOp is deprecated in [.../less.php/lib/Less/Parser.php:2464]
PHP Deprecated: Creation of dynamic property Less_Tree_Media::$allExtends is deprecated in [.../less.php/lib/Less/Visitor/extendFinder.php:96]
PHP Deprecated: Creation of dynamic property Less_Tree_Directive::$allExtends is deprecated in [.../less.php/lib/Less/Visitor/extendFinder.php:105]

Licensing

It's great that this library was picked up by wikimedia, however I wonder about the licensing. Is this code used in MediaWiki or any other GPLv2 licensed code? AFAIK the Apache license used by this project is not compatible with GPLv2.

There was some discussion years ago dual licensing the library at oyejorge#148 but the author was reluctant to do so because it was based on the orignal LESS code. A discussion on dual licensing there went nowhere: less/less.js#1029

So I am curious: are there any plans to review the license to make this library available to GPL licensed projects?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.