Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Better variable inheritance #584

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
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
34 changes: 31 additions & 3 deletions lessc.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -1940,6 +1940,9 @@ protected function set($name, $value) {
protected function get($name) {
$current = $this->env;

// track scope to evaluate
$scope_secondary = array();

$isArguments = $name == $this->vPrefix . 'arguments';
while ($current) {
if ($isArguments && isset($current->arguments)) {
Expand All @@ -1950,9 +1953,34 @@ protected function get($name) {
return $current->store[$name];
}

$current = isset($current->storeParent) ?
$current->storeParent :
$current->parent;
// has secondary scope?
if (isset($current->storeParent)) {
$scope_secondary[] = $current->storeParent;
}

$current = $current->parent;
}

// check secondary scopes
while ($scope_secondary) {
// pop scope off
$current = array_shift($scope_secondary);
while ($current) {
if ($isArguments && isset($current->arguments)) {
return array('list', ' ', $current->arguments);
}

if (isset($current->store[$name])) {
return $current->store[$name];
}

// has secondary scope?
if (isset($current->storeParent)) {
$scope_secondary[] = $current->storeParent;
}

$current = $current->parent;
}
}

$this->throwError("variable $name is undefined");
Expand Down