Skip to content

Commit 7756a30

Browse files
authored
Scan embedded_templates to locate additional functions
Add a check for `\Twig\Node\ModuleNode` instances when traversing the nodes. When found, grab the `embedded_templates` attribute, an array of `\Twig\Node\ModuleNode` instances for each embed or include in a template. Then loop and scan these as we do child nodes. This resolves #5 and allows for nested blocks to be scanned for functions.
1 parent 4726dd9 commit 7756a30

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

src/TwigFunctionsScanner.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
use Twig\Environment;
1616
use Twig\Source;
1717
use Twig\Node\Expression\FunctionExpression;
18+
use Twig\Node\ModuleNode;
1819

1920
class TwigFunctionsScanner implements FunctionsScannerInterface
2021
{
@@ -66,6 +67,14 @@ private function extractGettextFunctions($token, string $filename, array &$funct
6667
foreach ($token->getIterator() as $subToken) {
6768
$this->extractGettextFunctions($subToken, $filename, $functions);
6869
}
70+
71+
if($token instanceof ModuleNode){
72+
$embeddedTemplates = $token->getAttribute('embedded_templates');
73+
foreach($embeddedTemplates as $embed)
74+
{
75+
$this->extractGettextFunctions($embed, $filename, $functions);
76+
}
77+
}
6978
}
7079

7180
public function scan(string $code, string $filename): array

0 commit comments

Comments
 (0)