Skip to content

Commit

Permalink
imports done ahead of time to allow forward declaration of mixins fro…
Browse files Browse the repository at this point in the history
…m other files
  • Loading branch information
leafo committed Feb 26, 2012
1 parent 0b8aa30 commit 801eeca
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 13 deletions.
41 changes: 28 additions & 13 deletions lessc.inc.php
Expand Up @@ -975,6 +975,33 @@ function mergeBlock($target, $from) {
return $target;
}

// import all imports into the block
function mixImports($block) {
$props = array();
foreach ($block->props as $prop) {
if ($prop[0] == 'import') {
list(, $path) = $prop;
$this->addParsedFile($path);
$root = $this->createChild($path)->parseTree();

$root->parent = $block;
$this->mixImports($root);

// inject imported blocks into this block, local will overwrite import
$block->children = array_merge($root->children, $block->children);

// splice in all the props
foreach ($root->props as $sub_prop) {
// TODO fix the position to point to right file
$props[] = $sub_prop;
}
} else {
$props[] = $prop;
}
}
$block->props = $props;
}

/**
* Recursively compiles a block.
* @param $block the block
Expand Down Expand Up @@ -1016,6 +1043,7 @@ function compileBlock($block, $parent_tags = null) {

$lines = array();
$blocks = array();
$this->mixImports($block);
foreach ($block->props as $prop) {
$this->compileProp($prop, $block, $tags, $lines, $blocks);
}
Expand Down Expand Up @@ -1300,19 +1328,6 @@ function compileProp($prop, $block, $tags, &$_lines, &$_blocks) {
case 'raw':
$_lines[] = $prop[1];
break;
case 'import':
list(, $path) = $prop;
$this->addParsedFile($path);
$root = $this->createChild($path)->parseTree();

$root->parent = $block;
foreach ($root->props as $sub_prop) {
$this->compileProp($sub_prop, $root, $tags, $_lines, $_blocks);
}

// inject imported blocks into this block, local will overwrite import
$block->children = array_merge($root->children, $block->children);
break;
case 'charset':
list(, $value) = $prop;
$_lines[] = '@charset '.$this->compileValue($this->reduce($value)).';';
Expand Down
1 change: 1 addition & 0 deletions plessc
Expand Up @@ -147,6 +147,7 @@ function dumpValue($node, $depth = 0) {
}
return $out;
} elseif (is_array($node)) {
if (empty($node)) return "[]";
$type = $node[0];
if ($type == "block")
return dumpValue($node[1], $depth);
Expand Down

0 comments on commit 801eeca

Please sign in to comment.