| 1 |
<?php |
| 2 |
/** |
| 3 |
* @private |
| 4 |
* @see less-3.13.1.js#VariableCall |
| 5 |
* @todo missing allowRoot implementation https://github.com/less/less.js/commit/b67403d3 |
| 6 |
*/ |
| 7 |
class Less_Tree_VariableCall extends Less_Tree { |
| 8 |
|
| 9 |
/** @var string */ |
| 10 |
public $variable; |
| 11 |
/** @var string */ |
| 12 |
public $type = "VariableCall"; |
| 13 |
/** |
| 14 |
* @var int |
| 15 |
*/ |
| 16 |
private $index; |
| 17 |
/** |
| 18 |
* @var array |
| 19 |
*/ |
| 20 |
private $currentFileInfo; |
| 21 |
|
| 22 |
/** |
| 23 |
* @param string $variable |
| 24 |
*/ |
| 25 |
public function __construct( $variable, $index, $currentFileInfo ) { |
| 26 |
$this->variable = $variable; |
| 27 |
$this->index = $index; |
| 28 |
$this->currentFileInfo = $currentFileInfo; |
| 29 |
} |
| 30 |
|
| 31 |
public function accept( $visitor ) { |
| 32 |
} |
| 33 |
|
| 34 |
public function compile( $env ) { |
| 35 |
$detachedRuleset = ( new Less_Tree_Variable( $this->variable, $this->index, $this->currentFileInfo ) ) |
| 36 |
->compile( $env ); |
| 37 |
|
| 38 |
if ( !( $detachedRuleset instanceof Less_Tree_DetachedRuleset ) || !$detachedRuleset->ruleset ) { |
| 39 |
// order differs from upstream to simplify the code |
| 40 |
if ( is_array( $detachedRuleset ) ) { |
| 41 |
$rules = new Less_Tree_Ruleset( null, $detachedRuleset ); |
| 42 |
} elseif ( |
| 43 |
( $detachedRuleset instanceof Less_Tree_Ruleset |
| 44 |
|| $detachedRuleset instanceof Less_Tree_AtRule |
| 45 |
|| $detachedRuleset instanceof Less_Tree_Media |
| 46 |
|| $detachedRuleset instanceof Less_Tree_Mixin_Definition |
| 47 |
) && $detachedRuleset->rules |
| 48 |
) { |
| 49 |
// @todo - note looks like dead code, do we need it ? |
| 50 |
$rules = $detachedRuleset; |
| 51 |
} elseif ( $detachedRuleset instanceof Less_Tree && is_array( $detachedRuleset->value ) ) { |
| 52 |
// @phan-suppress-next-line PhanTypeMismatchArgument False positive |
| 53 |
$rules = new Less_Tree_Ruleset( null, $detachedRuleset->value ); |
| 54 |
} else { |
| 55 |
throw new Less_Exception_Compiler( 'Could not evaluate variable call ' . $this->variable ); |
| 56 |
} |
| 57 |
$detachedRuleset = new Less_Tree_DetachedRuleset( $rules ); |
| 58 |
} |
| 59 |
if ( $detachedRuleset->ruleset ) { |
| 60 |
return $detachedRuleset->callEval( $env ); |
| 61 |
} |
| 62 |
throw new Less_Exception_Compiler( 'Could not evaluate variable call ' . $this->variable ); |
| 63 |
} |
| 64 |
} |