From bcca533a1f785f5e89f5620f9aeba0c2a6abe045 Mon Sep 17 00:00:00 2001 From: Jensen Tonne Date: Fri, 27 Dec 2013 12:28:25 +0800 Subject: [PATCH] Accurate source file and line number when throwing undefined mixin or unknown block operation error. --- lessc.inc.php | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/lessc.inc.php b/lessc.inc.php index 1571fc23..70bf36aa 100644 --- a/lessc.inc.php +++ b/lessc.inc.php @@ -206,7 +206,7 @@ protected function compileBlock($block) { $this->compileNestedBlock($block, array($name)); break; default: - $this->throwError("unknown block type: $block->type\n"); + $block->parser->throwError("unknown block type: $block->type\n", $block->count); } } @@ -717,7 +717,7 @@ protected function compileProp($prop, $block, $out) { $mixins = $this->findBlocks($block, $path, $orderedArgs, $keywordArgs); if ($mixins === null) { - $this->throwError("{$prop[1][0]} is undefined"); + $block->parser->throwError("{$prop[1][0]} is undefined", $block->count); } foreach ($mixins as $mixin) { @@ -803,7 +803,7 @@ protected function compileProp($prop, $block, $out) { break; default: - $this->throwError("unknown op: {$prop[0]}\n"); + $block->parser->throwError("unknown op: {$prop[0]}\n", $block->count); } } @@ -1242,7 +1242,7 @@ protected function lib_contrast($args) { $darkColor = array('color', 0, 0, 0); $lightColor = array('color', 255, 255, 255); $threshold = 0.43; - + if ( $args[0] == 'list' ) { $inputColor = ( isset($args[2][0]) ) ? $this->assertColor($args[2][0]) : $lightColor; $darkColor = ( isset($args[2][1]) ) ? $this->assertColor($args[2][1]) : $darkColor; @@ -2364,7 +2364,7 @@ public function parse($buffer) { $this->throwError(); // TODO report where the block was opened - if ( !property_exists($this->env, 'parent') || !is_null($this->env->parent) ) + if ( !property_exists($this->env, 'parent') || !is_null($this->env->parent) ) throw new exception('parse error: unclosed block'); return $this->env; @@ -3569,6 +3569,14 @@ protected function pushBlock($selectors=null, $type=null) { $b->props = array(); $b->children = array(); + // add a reference to the parser so + // we can access the parser to throw errors + // or retrieve the sourceName of this block. + $b->parser = $this; + + // so we know the position of this block + $b->count = $this->count; + $this->env = $b; return $b; }