Skip to content

Commit d930b56

Browse files
committed
Use source parsed nodes to handle extends/include
1 parent 2189220 commit d930b56

1 file changed

Lines changed: 10 additions & 9 deletions

File tree

src/Phug/Tester/Coverage.php

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
namespace Phug\Tester;
44

5-
use Phug\Formatter\ElementInterface;
5+
use Phug\Ast\NodeInterface as AstNodeInterface;
66
use Phug\Parser\Node\DocumentNode;
77
use Phug\Parser\NodeInterface;
88
use Phug\Renderer;
@@ -279,24 +279,25 @@ protected function recordLocation(SourceLocationInterface $location = null, int
279279
}
280280
}
281281

282-
protected function listNodes(SplObjectStorage $list, ElementInterface $element)
282+
protected function listNodes(SplObjectStorage $list, $node)
283283
{
284-
$node = $element->getOriginNode();
285-
if ($node && !($node instanceof DocumentNode)) {
284+
if ($node instanceof NodeInterface && !($node instanceof DocumentNode) && !$list->offsetExists($node)) {
286285
$list->attach($node);
287286
$this->recordLocation($node->getSourceLocation());
288287
}
289-
290-
foreach ($element->getChildren() as $child) {
291-
if ($child instanceof ElementInterface) {
292-
static::listNodes($list, $child);
288+
if ($node instanceof AstNodeInterface) {
289+
foreach ($node->getChildren() as $child) {
290+
$this->listNodes($list, $child);
293291
}
294292
}
295293
}
296294

297295
protected function countFileNodes(string $file): int
298296
{
299-
$document = $this->renderer->getCompiler()->compileFileIntoElement($file);
297+
$compiler = $this->renderer->getCompiler();
298+
$file = $compiler->resolve($file);
299+
$contents = $compiler->getFileContents($file);
300+
$document = $this->renderer->getCompiler()->getParser()->parse($contents);
300301
$list = new SplObjectStorage();
301302

302303
$this->listNodes($list, $document);

0 commit comments

Comments
 (0)