Comments (1)
I've investigated this today, and conclude the following:
Less_Parser::getVariables
iterates on $this->rules
which is an array of rules as collected during the initial parse() or parseFiles() calls. These are not yet compiled, and thus will include @import
as unprocessed node at this point.
The documention of the original less.php project makes mention of the requirement to call getCSS()
before calling getVariables()
so that values that have non-literal values (e.g. composed of other variables, or that use a calculation or expression of some kind, or are imported from other files) can be seen.
When getCSS()
performs the compilation, it creates a new tree ($evaldRoot
). As such, the rules that are being iterated by getVariables()
continue to reflect only the direct assignments in the top-level parsed files or content.
I explored a few ways to making this work:
- Assign
$evaldRoot
to an instance member before the end ofgetCSS()
, and updategetVariables()
to iterate$this->evaldRoot->rules
instead of$this->rules
. This doesn't work because compilation phase not only evaluates and flattens imported files and computed expressions in variable values, theLess_Visitor_toCSS
post visitor also effectively discards and removes any trace of the Less_Tree_Variable objects or their transformedLess_Tree_Rule->variable === true
equivalents, because they produce no CSS output. - Track variables in the Less_Environment object. This is actually already done. When the compiler finds an expression in Less that refers to a variable, that reference is represented by
Less_Tree_Variable
and Less_Tree_Variable::compileuses
$env->frames[…]->variable()to find a matching value. But, by the time
getCSS()is done,
Environment->$frame` is empty. This makes sense because the compiler is no longer inside any file context, and the Less specification requires variables to depend on lexical scope. Variables may be limited to particular files or rulesets only. So when we are no longer in a file, there are no longer any variables in scope. - Keep track of the last frame in Less_Environment before we shift it out of memory. Or, alternatively, assign
$evaldRoot
before theLess_Visitor_toCSS
phase happens ingetCSS()
. Both of these approaches would result in us keeping a reference to the expanded Tree which at that point in time has all the variable values in the global scope, and has not yet discarded these as part of producing CSS output. The problem with this approach is thatLess_Visitor_toCSS
actually modifies the tree in-place. While the compiler takes care to keep the compiled and originalrules
tree separate, it has no reason for internal compilation steps to not simply do the most optimal thing and modify the tree in-place. This means by the timegetCSS()
is finished, there are no longer redundant things in the tree such as Less_Tree_Rule objects that represent variable assignments.
from less.php.
Related Issues (20)
- PHP 8.2 Creation of dynamic property warning HOT 2
- Tree_Javascript or Tree_JavaScript? HOT 6
- Allowed memory limit exceeded when unserializing cache. HOT 4
- Support CSS `@property` rule (Less.js 3.0.0) HOT 2
- Block comments in @font-face are moved to bottom of selector HOT 3
- Regression in v4.2.0 HOT 6
- Regression: CSS output differs from Less.js for mixin selector HOT 3
- Undefined array key "currentUri" in [...]Mapped.php Line 68 when using @import (inline) HOT 1
- Trying to access array offset on value of type null HOT 1
- Support logical if() function (Less.js 3.0) HOT 3
- Parser Exception parsing "filter: alpha(opacity=0);" HOT 2
- Cannot assign em or rem value to less variable. HOT 2
- Support @container queries (Less.js 4.2.0) HOT 1
- Import from google font HOT 3
- Deprecation warning in PHP 8.2 HOT 6
- if $cached_name is the same as the $compiled name, should not regenerate HOT 1
- Error in Compiling HOT 2
- @container queries support? HOT 2
- Support CSS4 space-separated syntax for rgba() function (Less.js 3.8.1) HOT 1
- Autoloading can fail due to incorrect class name casing HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from less.php.