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

Accurate file and line number when throwing undefined mixin or unknown block operation error. #524

Open
wants to merge 1 commit 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
18 changes: 13 additions & 5 deletions lessc.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}

Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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);
}
}

Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
}
Expand Down