Skip to content

Commit b5dff5b

Browse files
matheoweaverryan
authored andcommitted
Ignore twig comments when prelexing
1 parent b19a903 commit b5dff5b

File tree

2 files changed

+13
-0
lines changed

2 files changed

+13
-0
lines changed

src/TwigComponent/src/Twig/TwigPreLexer.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,14 @@ public function preLexComponents(string $input, bool $insideOfBlock = false): st
4040
$output = '';
4141

4242
while ($this->position < $this->length) {
43+
// ignore content inside twig comments, see #838
44+
if ($this->consume('{#')) {
45+
$output .= '{#';
46+
$output .= $this->consumeUntil('#}');
47+
$this->consume('#}');
48+
$output .= '#}';
49+
}
50+
4351
if ($this->consume('<twig:')) {
4452
$componentName = $this->consumeComponentName();
4553

src/TwigComponent/tests/Unit/TwigPreLexerTest.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,5 +166,10 @@ public function getLexTests(): iterable
166166
'<twig:foobar my:attribute="yo"></twig:foobar>',
167167
'{% component \'foobar\' with { \'my:attribute\': \'yo\' } %}{% endcomponent %}',
168168
];
169+
170+
yield 'ignore_twig_comment' => [
171+
'{# <twig:Alert/> #} <twig:Alert/>',
172+
'{# <twig:Alert/> #} {{ component(\'Alert\') }}',
173+
];
169174
}
170175
}

0 commit comments

Comments
 (0)