Skip to content
This repository was archived by the owner on Dec 5, 2019. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
18 commits
Select commit Hold shift + click to select a range
4106ccc
some improvment on providing cache_string
Cerdic Oct 16, 2018
7aaa104
currentFileInfo is poped and pushed in the parse() function, so it ca…
Cerdic Oct 16, 2018
afa9a36
attempt to Fix import reference
Cerdic Oct 16, 2018
deaad68
attempt to Fix import reference
Cerdic Oct 16, 2018
0d07c1a
Less_Tree_Anonymous:no local reference to currentFileInfo, using stat…
Cerdic Oct 16, 2018
e8071d4
Less_Tree_Comment: no local reference to currentFileInfo, using stati…
Cerdic Oct 16, 2018
05533d5
Less_Exception_Compiler: no local reference to currentFileInfo, using…
Cerdic Oct 16, 2018
cb5e123
Less_Tree_Element: no local reference to currentFileInfo, using stati…
Cerdic Oct 16, 2018
e770fbe
Less_Exception_Compiler: no local reference to currentFileInfo, using…
Cerdic Oct 16, 2018
c07c4dc
Less_Tree_Selector: no local reference to currentFileInfo, using stat…
Cerdic Oct 16, 2018
dda8e8a
Less_Tree_Url: no local reference to currentFileInfo, using static Le…
Cerdic Oct 16, 2018
930d0fa
Less_Tree_NameValue: no local reference to currentFileInfo, using sta…
Cerdic Oct 16, 2018
a20d6de
Less_Tree_Quoted: no local reference to currentFileInfo, using static…
Cerdic Oct 16, 2018
cfba744
Less_Tree_Call: no local reference to currentFileInfo, using static L…
Cerdic Oct 16, 2018
559f5b0
Less_Tree_Mixin_Call: no local reference to currentFileInfo, using st…
Cerdic Oct 16, 2018
cbec718
Less_Tree_Media: no local reference to currentFileInfo, using static …
Cerdic Oct 16, 2018
56a2894
Less_Tree_Directive: no local reference to currentFileInfo, using sta…
Cerdic Oct 16, 2018
cd375ef
small optimizations
Cerdic Oct 16, 2018
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/Less/Environment.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ class Less_Environment{
//public $processImports; // option - whether to process imports. if false then imports will not be imported
//public $javascriptEnabled; // option - whether JavaScript is enabled. if undefined, defaults to true
//public $useFileCache; // browser only - whether to use the per file session cache
public $currentFileInfo; // information about the current file - for error reporting and importing and making urls relative etc.
public static $currentFileInfo; // information about the current file - for error reporting and importing and making urls relative etc.

public $importMultiple = false; // whether we are currently importing multiple copies

Expand Down
2 changes: 1 addition & 1 deletion lib/Less/Functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -911,7 +911,7 @@ public function datauri($mimetypeNode, $filePathNode = null ) {
$DATA_URI_MAX_KB = 32;
$fileSizeInKB = round( strlen($buf) / 1024 );
if( $fileSizeInKB >= $DATA_URI_MAX_KB ){
$url = new Less_Tree_Url( ($filePathNode ? $filePathNode : $mimetypeNode), $this->currentFileInfo);
$url = new Less_Tree_Url( ($filePathNode ? $filePathNode : $mimetypeNode), $this->currentFileInfo['uri_root'] );
return $url->compile($this);
}

Expand Down
93 changes: 49 additions & 44 deletions lib/Less/Parser.php
Original file line number Diff line number Diff line change
Expand Up @@ -441,15 +441,15 @@ public function parse( $str, $file_uri = null ){
$uri_root = dirname($file_uri);
}

$previousFileInfo = $this->env->currentFileInfo;
$previousFileInfo = Less_Environment::$currentFileInfo;
$uri_root = self::WinPath($uri_root);
$this->SetFileInfo($filename, $uri_root);

$this->input = $str;
$this->_parse();

if( $previousFileInfo ){
$this->env->currentFileInfo = $previousFileInfo;
Less_Environment::$currentFileInfo = $previousFileInfo;
}

return $this;
Expand All @@ -465,7 +465,7 @@ public function parse( $str, $file_uri = null ){
* @param bool $returnRoot Indicates whether the return value should be a css string a root node
* @return Less_Tree_Ruleset|Less_Parser
*/
public function parseFile( $filename, $uri_root = '', $returnRoot = false){
public function parseFile( $filename, $uri_root = '', $returnRoot = false, $reference = null){

if( !file_exists($filename) ){
$this->Error(sprintf('File `%s` not found.', $filename));
Expand All @@ -479,7 +479,7 @@ public function parseFile( $filename, $uri_root = '', $returnRoot = false){
}


$previousFileInfo = $this->env->currentFileInfo;
$previousFileInfo = Less_Environment::$currentFileInfo;


if( $filename ){
Expand All @@ -488,6 +488,9 @@ public function parseFile( $filename, $uri_root = '', $returnRoot = false){
$uri_root = self::WinPath($uri_root);

$this->SetFileInfo($filename, $uri_root);
if (!is_null($reference)) {
Less_Environment::$currentFileInfo['reference'] = $reference;
}

self::AddParsedFile($filename);

Expand All @@ -500,7 +503,7 @@ public function parseFile( $filename, $uri_root = '', $returnRoot = false){
}

if( $previousFileInfo ){
$this->env->currentFileInfo = $previousFileInfo;
Less_Environment::$currentFileInfo = $previousFileInfo;
}

return $return;
Expand Down Expand Up @@ -536,10 +539,10 @@ public function SetFileInfo( $filename, $uri_root = ''){
$currentFileInfo = array();

//entry info
if( isset($this->env->currentFileInfo) ){
$currentFileInfo['entryPath'] = $this->env->currentFileInfo['entryPath'];
$currentFileInfo['entryUri'] = $this->env->currentFileInfo['entryUri'];
$currentFileInfo['rootpath'] = $this->env->currentFileInfo['rootpath'];
if( isset(Less_Environment::$currentFileInfo) ){
$currentFileInfo['entryPath'] = Less_Environment::$currentFileInfo['entryPath'];
$currentFileInfo['entryUri'] = Less_Environment::$currentFileInfo['entryUri'];
$currentFileInfo['rootpath'] = Less_Environment::$currentFileInfo['rootpath'];

}else{
$currentFileInfo['entryPath'] = $dirname;
Expand All @@ -551,14 +554,15 @@ public function SetFileInfo( $filename, $uri_root = ''){
$currentFileInfo['currentUri'] = $uri_root.basename($filename);
$currentFileInfo['filename'] = $filename;
$currentFileInfo['uri_root'] = $uri_root;
$currentFileInfo['reference'] = null;


//inherit reference
if( isset($this->env->currentFileInfo['reference']) && $this->env->currentFileInfo['reference'] ){
if( isset(Less_Environment::$currentFileInfo['reference']) && Less_Environment::$currentFileInfo['reference'] ){
$currentFileInfo['reference'] = true;
}

$this->env->currentFileInfo = $currentFileInfo;
Less_Environment::$currentFileInfo = $currentFileInfo;
}


Expand Down Expand Up @@ -674,7 +678,7 @@ private function GetRules( $file_path ){
$rules = $this->parsePrimary();

if( $this->pos < $this->input_len ){
throw new Less_Exception_Chunk($this->input, null, $this->furthest, $this->env->currentFileInfo);
throw new Less_Exception_Chunk($this->input, null, $this->furthest, Less_Environment::$currentFileInfo);
}

$this->UnsetInput();
Expand Down Expand Up @@ -730,8 +734,8 @@ public function SetInput( $file_path ){
$this->input_len = strlen($this->input);


if( Less_Parser::$options['sourceMap'] && $this->env->currentFileInfo ){
$uri = $this->env->currentFileInfo['currentUri'];
if( Less_Parser::$options['sourceMap'] && Less_Environment::$currentFileInfo ){
$uri = Less_Environment::$currentFileInfo['currentUri'];
Less_Parser::$contentsMap[$uri] = $this->input;
}

Expand Down Expand Up @@ -875,7 +879,7 @@ private function MatchChar($tok){
// Match a regexp from the current start point
private function MatchReg($tok){

if( preg_match($tok, $this->input, $match, 0, $this->pos) ){
if( preg_match($tok . "S", $this->input, $match, 0, $this->pos) ){
$this->skipWhitespace(strlen($match[0]));
return $match;
}
Expand Down Expand Up @@ -912,7 +916,7 @@ public function skipWhitespace($length){
for(; $this->pos < $this->input_len; $this->pos++ ){
$c = $this->input[$this->pos];

if( ($c !== "\n") && ($c !== "\r") && ($c !== "\t") && ($c !== ' ') ){
if( strpos( "\n\r\t ", $c ) === false ){
break;
}
}
Expand Down Expand Up @@ -1035,13 +1039,13 @@ private function parseComment(){

if( $this->input[$this->pos+1] === '/' ){
$match = $this->MatchReg('/\\G\/\/.*/');
return $this->NewObj4('Less_Tree_Comment',array($match[0], true, $this->pos, $this->env->currentFileInfo));
return $this->NewObj4('Less_Tree_Comment',array($match[0], true, $this->pos, Less_Environment::$currentFileInfo['reference']));
}

//$comment = $this->MatchReg('/\\G\/\*(?:[^*]|\*+[^\/*])*\*+\/\n?/');
$comment = $this->MatchReg('/\\G\/\*(?s).*?\*+\/\n?/');//not the same as less.js to prevent fatal errors
if( $comment ){
return $this->NewObj4('Less_Tree_Comment',array($comment[0], false, $this->pos, $this->env->currentFileInfo));
return $this->NewObj4('Less_Tree_Comment',array($comment[0], false, $this->pos, Less_Environment::$currentFileInfo['reference']));
}
}

Expand Down Expand Up @@ -1093,7 +1097,7 @@ private function parseEntitiesQuoted() {
}

$quoted = $char.$matched.$char;
return $this->NewObj5('Less_Tree_Quoted',array($quoted, $matched, $e, $index, $this->env->currentFileInfo) );
return $this->NewObj4('Less_Tree_Quoted',array($quoted, $matched, $e, $index) );
}


Expand Down Expand Up @@ -1209,7 +1213,7 @@ private function parseEntitiesCall(){
}

if ($name) {
return $this->NewObj4('Less_Tree_Call',array($name, $args, $index, $this->env->currentFileInfo) );
return $this->NewObj3('Less_Tree_Call',array($name, $args, $index) );
}
}

Expand Down Expand Up @@ -1285,10 +1289,10 @@ private function parseEntitiesUrl(){


if( isset($value->value) || $value instanceof Less_Tree_Variable ){
return $this->NewObj2('Less_Tree_Url',array($value, $this->env->currentFileInfo));
return $this->NewObj2('Less_Tree_Url', array($value, Less_Environment::$currentFileInfo['uri_root']) );
}

return $this->NewObj2('Less_Tree_Url', array( $this->NewObj1('Less_Tree_Anonymous',$value), $this->env->currentFileInfo) );
return $this->NewObj2('Less_Tree_Url', array($this->NewObj1('Less_Tree_Anonymous',$value), Less_Environment::$currentFileInfo['uri_root']) );
}


Expand All @@ -1303,7 +1307,7 @@ private function parseEntitiesUrl(){
private function parseEntitiesVariable(){
$index = $this->pos;
if ($this->PeekChar('@') && ($name = $this->MatchReg('/\\G@@?[\w-]+/'))) {
return $this->NewObj3('Less_Tree_Variable', array( $name[0], $index, $this->env->currentFileInfo));
return $this->NewObj2('Less_Tree_Variable', array( $name[0], $index));
}
}

Expand All @@ -1313,7 +1317,7 @@ private function parseEntitiesVariableCurly() {
$index = $this->pos;

if( $this->input_len > ($this->pos+1) && $this->input[$this->pos] === '@' && ($curly = $this->MatchReg('/\\G@\{([\w-]+)\}/')) ){
return $this->NewObj3('Less_Tree_Variable',array('@'.$curly[1], $index, $this->env->currentFileInfo));
return $this->NewObj2('Less_Tree_Variable',array('@'.$curly[1], $index));
}
}

Expand Down Expand Up @@ -1495,7 +1499,7 @@ private function parseMixinCall(){

if( $this->parseEnd() ){
$this->forget();
return $this->NewObj5('Less_Tree_Mixin_Call', array( $elements, $args, $index, $this->env->currentFileInfo, $important));
return $this->NewObj5('Less_Tree_Mixin_Call', array( $elements, $args, $index, Less_Environment::$currentFileInfo['reference'], $important));
}
}

Expand All @@ -1513,7 +1517,7 @@ private function parseMixinCallElements(){
if( !$e ){
break;
}
$elements[] = $this->NewObj4('Less_Tree_Element', array($c, $e[0], $elemIndex, $this->env->currentFileInfo));
$elements[] = $this->NewObj3('Less_Tree_Element', array($c, $e[0], $elemIndex));
$c = $this->MatchChar('>');
}

Expand Down Expand Up @@ -1811,7 +1815,7 @@ private function parseElement(){
}

if( !is_null($e) ){
return $this->NewObj4('Less_Tree_Element',array( $c, $e, $index, $this->env->currentFileInfo));
return $this->NewObj3('Less_Tree_Element',array( $c, $e, $index));
}
}

Expand Down Expand Up @@ -1893,7 +1897,7 @@ private function parseSelector( $isLess = false ){
}

if( $elements ){
return $this->NewObj5('Less_Tree_Selector',array($elements, $extendList, $condition, $index, $this->env->currentFileInfo));
return $this->NewObj5('Less_Tree_Selector',array($elements, $extendList, $condition, $index, Less_Environment::$currentFileInfo['reference']));
}
if( $extendList ) {
$this->Error('Extend must be used to extend a selector, it cannot be used on its own');
Expand Down Expand Up @@ -2023,7 +2027,7 @@ private function parseNameValue(){
$match[2] .= ' !important';
}

return $this->NewObj4('Less_Tree_NameValue',array( $match[1], $match[2], $index, $this->env->currentFileInfo));
return $this->NewObj3('Less_Tree_NameValue',array( $match[1], $match[2], $index));
}

$this->restore();
Expand Down Expand Up @@ -2080,7 +2084,7 @@ private function parseRule( $tryAnonymous = null ){

if( $value && $this->parseEnd() ){
$this->forget();
return $this->NewObj6('Less_Tree_Rule',array( $name, $value, $important, $merge, $startOfRule, $this->env->currentFileInfo));
return $this->NewObj5('Less_Tree_Rule',array( $name, $value, $important, $merge, $startOfRule));
}else{
$this->furthest = $this->pos;
$this->restore();
Expand Down Expand Up @@ -2115,7 +2119,9 @@ private function parseImport(){

$this->save();

$dir = $this->MatchReg('/\\G@import?\s+/');
$dir = '';
if ($this->PeekChar('@'))
$dir = $this->MatchReg('/\\G@import?\s+/');

if( $dir ){
$options = $this->parseImportOptions();
Expand All @@ -2129,7 +2135,7 @@ private function parseImport(){
}

$this->forget();
return $this->NewObj5('Less_Tree_Import',array( $path, $features, $options, $this->pos, $this->env->currentFileInfo));
return $this->NewObj5('Less_Tree_Import',array( $path, $features, $options, $this->pos, Less_Environment::$currentFileInfo));
}
}
}
Expand Down Expand Up @@ -2186,7 +2192,7 @@ private function parseMediaFeature() {
$e = $this->parseValue();
if ($this->MatchChar(')')) {
if ($p && $e) {
$r = $this->NewObj7('Less_Tree_Rule', array( $p, $e, null, null, $this->pos, $this->env->currentFileInfo, true));
$r = $this->NewObj6('Less_Tree_Rule', array( $p, $e, null, null, $this->pos, true));
$nodes[] = $this->NewObj1('Less_Tree_Paren',$r);
} elseif ($e) {
$nodes[] = $this->NewObj1('Less_Tree_Paren',$e);
Expand Down Expand Up @@ -2224,12 +2230,12 @@ private function parseMediaFeatures() {
}

private function parseMedia() {
if( $this->MatchReg('/\\G@media/') ){
if( $this->PeekChar('@') && $this->MatchReg('/\\G@media/') ){
$features = $this->parseMediaFeatures();
$rules = $this->parseBlock();

if( is_array($rules) ){
return $this->NewObj4('Less_Tree_Media',array( $rules, $features, $this->pos, $this->env->currentFileInfo));
return $this->NewObj3('Less_Tree_Media',array( $rules, $features, $this->pos));
}
}
}
Expand Down Expand Up @@ -2340,7 +2346,7 @@ private function parseDirective(){

if( $rules || (!$hasBlock && $value && $this->MatchChar(';'))) {
$this->forget();
return $this->NewObj5('Less_Tree_Directive',array($name, $value, $rules, $index, $this->env->currentFileInfo));
return $this->NewObj5('Less_Tree_Directive',array($name, $value, $rules, $index, Less_Environment::$currentFileInfo['reference']));
}

$this->restore();
Expand Down Expand Up @@ -2624,7 +2630,7 @@ private function parseRuleProperty(){
if( !$s || $s[0] !== '@' ){
$name[$k] = $this->NewObj1('Less_Tree_Keyword',$s);
}else{
$name[$k] = $this->NewObj3('Less_Tree_Variable',array('@' . substr($s,2,-1), $index[$k], $this->env->currentFileInfo));
$name[$k] = $this->NewObj2('Less_Tree_Variable',array('@' . substr($s,2,-1), $index[$k]));
}
}
return $name;
Expand Down Expand Up @@ -2701,7 +2707,7 @@ public function NewObj0($class){
public function NewObj1($class, $arg){
$obj = new $class( $arg );
if( $this->CacheEnabled() ){
$obj->cache_string = ' new '.$class.'('.Less_Parser::ArgString($arg).')';
$obj->cache_string = ' new '.$class.'('. (is_scalar($arg) ? var_export($arg, true) : Less_Parser::ArgString($arg)) .')';
}
return $obj;
}
Expand Down Expand Up @@ -2771,17 +2777,16 @@ public function ArgCache($args){
*/
public static function ArgString($arg){

$type = gettype($arg);

if( $type === 'object'){
if( is_object($arg) ){
$string = $arg->cache_string;
unset($arg->cache_string);
return $string;

}elseif( $type === 'array' ){
}
elseif( is_array($arg) ){
$string = ' Array(';
foreach($arg as $k => $a){
$string .= var_export($k,true).' => '.self::ArgString($a).',';
$string .= var_export($k,true).' => '.(is_scalar($a) ? var_export($a,true) : self::ArgString($a)).',';
}
return $string . ')';
}
Expand All @@ -2790,7 +2795,7 @@ public static function ArgString($arg){
}

public function Error($msg){
throw new Less_Exception_Parser($msg, null, $this->furthest, $this->env->currentFileInfo);
throw new Less_Exception_Parser($msg, null, $this->furthest, Less_Environment::$currentFileInfo);
}

public static function WinPath($path){
Expand Down
8 changes: 3 additions & 5 deletions lib/Less/Tree/Anonymous.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,22 +11,20 @@ class Less_Tree_Anonymous extends Less_Tree{
public $quote;
public $index;
public $mapLines;
public $currentFileInfo;
public $type = 'Anonymous';

/**
* @param integer $index
* @param boolean $mapLines
*/
public function __construct($value, $index = null, $currentFileInfo = null, $mapLines = null ){
public function __construct($value, $index = null, $mapLines = null ){
$this->value = $value;
$this->index = $index;
$this->mapLines = $mapLines;
$this->currentFileInfo = $currentFileInfo;
}

public function compile(){
return new Less_Tree_Anonymous($this->value, $this->index, $this->currentFileInfo, $this->mapLines);
return new Less_Tree_Anonymous($this->value, $this->index, $this->mapLines);
}

public function compare($x){
Expand All @@ -48,7 +46,7 @@ public function compare($x){
* @see Less_Tree::genCSS
*/
public function genCSS( $output ){
$output->add( $this->value, $this->currentFileInfo, $this->index, $this->mapLines );
$output->add( $this->value, Less_Environment::$currentFileInfo, $this->index, $this->mapLines );
}

public function toCSS(){
Expand Down
Loading