protected $indentation;
protected $env;
protected $debugInfo;
+ protected $sourceOffset;
+ protected $sourceLine;
/**
* Constructor.
{
$this->lastLine = null;
$this->source = '';
+ $this->sourceOffset = 0;
+ $this->sourceLine = 0;
$this->indentation = $indentation;
$node->compile($this);
public function addDebugInfo(Twig_NodeInterface $node)
{
if ($node->getLine() != $this->lastLine) {
- $this->debugInfo[substr_count($this->source, "\n")] = $node->getLine();
+ $this->sourceLine += substr_count($this->source, "\n", $this->sourceOffset);
+ $this->sourceOffset = strlen($this->source);
+ $this->debugInfo[$this->sourceLine] = $node->getLine();
$this->lastLine = $node->getLine();
$this->write("// line {$node->getLine()}\n");