mirror of
https://github.com/twigphp/Twig.git
synced 2026-09-14 11:27:00 +00:00
merged branch char101/fix-debug-lineno (PR #894)
This PR was squashed before being merged into the master branch (closes #894).
Commits
-------
7c5854b Fix twig error lineno off by 2
Discussion
----------
Fix twig error lineno off by 2
It seems to me that the lineno reported by Twig_Error is off by 2 from the real lineno in the generated PHP source
For example:
```
{% if true %}
Yes
{% endif %}
```
```php
<?php
/* */
class __TwigTemplate_d41d8cd98f00b204e9800998ecf8427e extends Twig_Template
{
public function __construct(Twig_Environment $env)
{
parent::__construct($env);
$this->parent = false;
$this->blocks = array(
);
}
protected function doDisplay(array $context, array $blocks = array())
{
// line 1
if (true) { // <- this is line 19
// line 2
echo "Yes // <- this is line 21
";
}
}
public function getTemplateName()
{
return null;
}
public function isTraitable()
{
return false;
}
public function getDebugInfo()
{
return array ( 19 => 2, 17 => 1,); // <- should be return array ( 21 => 2, 19 => 1,);
}
}
```
---------------------------------------------------------------------------
by char101 at 2012-11-08T08:23:57Z
Since `$compiler->addDebugInfo()` is called first before writing the node content, usually the number of lines in the PHP code is less than 2 (1 for the // lineno comment, and 1 for the generated content) than the line where the node content is written.
This commit is contained in:
@@ -217,7 +217,7 @@ class Twig_Compiler implements Twig_CompilerInterface
|
||||
$this->sourceLine += substr_count($this->source, "\n", $this->sourceOffset);
|
||||
}
|
||||
$this->sourceOffset = strlen($this->source);
|
||||
$this->debugInfo[$this->sourceLine] = $node->getLine();
|
||||
$this->debugInfo[$this->sourceLine + 2] = $node->getLine();
|
||||
|
||||
$this->lastLine = $node->getLine();
|
||||
$this->write("// line {$node->getLine()}\n");
|
||||
|
||||
@@ -90,7 +90,7 @@ class __TwigTemplate_be925a7b06dda0dfdbd18a1509f7eb34 extends Twig_Template
|
||||
|
||||
public function getDebugInfo()
|
||||
{
|
||||
return array ( 17 => 1,);
|
||||
return array ( 19 => 1,);
|
||||
}
|
||||
}
|
||||
EOF
|
||||
@@ -142,7 +142,7 @@ class __TwigTemplate_be925a7b06dda0dfdbd18a1509f7eb34 extends Twig_Template
|
||||
|
||||
public function getDebugInfo()
|
||||
{
|
||||
return array ( 22 => 1,);
|
||||
return array ( 24 => 1,);
|
||||
}
|
||||
}
|
||||
EOF
|
||||
|
||||
@@ -98,7 +98,7 @@ class __TwigTemplate_be925a7b06dda0dfdbd18a1509f7eb34 extends Twig_Template
|
||||
|
||||
public function getDebugInfo()
|
||||
{
|
||||
return array ( 18 => 1,);
|
||||
return array ( 20 => 1,);
|
||||
}
|
||||
}
|
||||
EOF
|
||||
|
||||
Reference in New Issue
Block a user