From: Fabien Potencier Date: Thu, 8 Nov 2012 09:24:49 +0000 (+0100) Subject: tweaked previous merge (refs #894) X-Git-Url: http://git.silmor.de/gitweb/?a=commitdiff_plain;h=1a10ea2fbb2291142b4ee03665591c0762315204;p=web%2Fkonrad%2Ftwig.git tweaked previous merge (refs #894) --- diff --git a/CHANGELOG b/CHANGELOG index 5c8a3d8..4e61084 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,5 +1,6 @@ * 1.11.1 (2012-XX-XX) + * fixed debug info line numbering (was off by 2) * fixed escaping when calling a macro inside another one (regression introduced in 1.9.1) * optimized variable access on PHP 5.4 * fixed a crash of the C extension when an exception was thrown from a macro called without being imported (using _self.XXX) diff --git a/lib/Twig/Compiler.php b/lib/Twig/Compiler.php index a6868b2..c1ab250 100644 --- a/lib/Twig/Compiler.php +++ b/lib/Twig/Compiler.php @@ -76,7 +76,8 @@ class Twig_Compiler implements Twig_CompilerInterface $this->lastLine = null; $this->source = ''; $this->sourceOffset = 0; - $this->sourceLine = 0; + // source code starts at 1 (as we then increment it when we encounter new lines) + $this->sourceLine = 1; $this->indentation = $indentation; if ($node instanceof Twig_Node_Module) { @@ -207,6 +208,8 @@ class Twig_Compiler implements Twig_CompilerInterface public function addDebugInfo(Twig_NodeInterface $node) { if ($node->getLine() != $this->lastLine) { + $this->write("// line {$node->getLine()}\n"); + // when mbstring.func_overload is set to 2 // mb_substr_count() replaces substr_count() // but they have different signatures! @@ -217,10 +220,9 @@ class Twig_Compiler implements Twig_CompilerInterface $this->sourceLine += substr_count($this->source, "\n", $this->sourceOffset); } $this->sourceOffset = strlen($this->source); - $this->debugInfo[$this->sourceLine + 2] = $node->getLine(); + $this->debugInfo[$this->sourceLine] = $node->getLine(); $this->lastLine = $node->getLine(); - $this->write("// line {$node->getLine()}\n"); } return $this;