This is an overview of the high-level steps during the transformation from Less to CSS, and how they compare between Less.js and Less.php.
Less.js:
less.render(input, { paths: … })
Parser.parse
normalizes inputParser.parse
parses input into rules viaparsers.primary
Parser.parse
creates the "root" ruleset objectParser.parse
applies ImportVisitorImportVisitor
applies these steps to eachImport
node:ImportVisitor#processImportNode
Import#evalForImport
ImportVisitor
ends withImporVisitor#tryRun
loop (async, after last call toImportVisitor#onImported
.
less.render
callbackParseTree.prototype.toCSS
transformTree
applies pre-visitors, compiles all rules, and applies post-visitors.
ParseTree.prototype.toCSS
runs toCSS transform on the "root" ruleset.
- CSS result ready!
Less.php
Less_Parser->parseFile
Less_Parser->_parse
Less_Parser->GetRules
normalizes input (viaLess_Parser->SetInput
)Less_Parser->GetRules
parses input into rules viaLess_Parser->parsePrimary
Less_Parser->getCss
Less_Parser->getCss
creates the "root" ruleset objectLess_Parser->getCss
applies Less_ImportVisitorLess_ImportVisitor
applies these steps to eachImport
node:ImportVisitor->processImportNode
Less_Tree_Import->compileForImport
ImportVisitor
ends withImporVisitor#tryRun
loop (all sync, no async needed).
Less_Parser->getCss
applies pre-visitors, compiles all rules, and applies post-visitors.Less_Parser->getCss
runs toCSS transform on the "root" ruleset.
- CSS result ready!
The wikimedia/less.php
package inherits a long history of loosely compatible
and interchangable Less compilers written in PHP.
Starting with less.php v3.2.1 (released in 2023), the public API is more clearly
documented, and internal code is now consistently marked @private
.
The public API includes the Less_Parser
class and several of its public methods.
For legacy reasons, some of its internal methods remain public. Maintainers must
take care to search the following downstream applications when changing or
removing public methods. If a method has one or more references in the below
codebases, treat it as a breaking change and document a migration path in the
commit message (and later in CHANGES.md), even if the method was undocumented
or feels like it is for internal use only.