vendor/lib/visitor/evaluator.js in stylus-source-0.41.1 vs vendor/lib/visitor/evaluator.js in stylus-source-0.41.2

- old
+ new

@@ -661,15 +661,19 @@ if (ok.isTrue) { ret = this.visit(node.block); // else } else if (node.elses.length) { var elses = node.elses - , len = elses.length; + , len = elses.length + , cond; for (var i = 0; i < len; ++i) { // else if if (elses[i].cond) { - if (this.visit(elses[i]).first.toBoolean().isTrue) { + this.return++; + cond = this.visit(elses[i].cond).first.toBoolean(); + this.return--; + if (cond.isTrue) { ret = this.visit(elses[i].block); break; } // else } else { @@ -696,12 +700,14 @@ Evaluator.prototype.visitExtend = function(extend){ // Cloning the selector for when we are in a loop and don't want it to affect // the selector nodes and cause the values to be different to expected var selector = this.interpolate(extend.selector.clone()); - var block = !this.currentBlock.node.extends && this.targetBlock.node.extends ? this.targetBlock : this.currentBlock; - if (!block.node.extends && this.extendBlock) block = this.extendBlock; + var block = this.currentBlock; + if ('group' != block.node.nodeName) { + block = this.targetBlock && this.targetBlock.node.extends ? this.targetBlock : this.closestGroup; + } block.node.extends.push(selector); return nodes.null; }; /** @@ -919,27 +925,22 @@ * @api private */ Evaluator.prototype.invoke = function(body, stack, filename){ var self = this - , ret - , node; + , ret; if (filename) this.paths.push(dirname(filename)); // Return if (this.return) { ret = this.eval(body.nodes); if (stack) this.stack.pop(); // Mixin } else { var targetFrame = this.stack[this.stack.length - 2]; - if (targetFrame) { - this.targetBlock = targetFrame.block; - node = this.targetBlock.node; - if (node && node.extends) this.extendBlock = this.targetBlock; - } + if (targetFrame) this.targetBlock = targetFrame.block; body = this.visit(body); if (stack) this.stack.pop(); this.mixin(body.nodes, this.currentBlock); ret = nodes.null; } @@ -1119,10 +1120,14 @@ block = this.stack[i].block; if (!block.node) continue; switch (block.node.nodeName) { case 'group': case 'function': + case 'if': + case 'each': + case 'fontface': + case 'page': nodes = block.nodes; // scan siblings from the property index up if (i + 1 == top) { while (index--) { other = this.interpolate(nodes[index]); @@ -1161,9 +1166,27 @@ case 'group': case 'function': case 'media': return block; } + } + } +}); + +/** + * Return the closest group block. + * + * @return {Block} + * @api private + */ + +Evaluator.prototype.__defineGetter__('closestGroup', function(){ + var i = this.stack.length + , block; + while (i--) { + block = this.stack[i].block; + if (block.node && 'group' == block.node.nodeName) { + return block; } } }); /**