Skip to content

Commit 5cb67cc

Browse files
committed
Fix data-twig-remove with v-if or v-for
1 parent 03ed49f commit 5cb67cc

File tree

2 files changed

+24
-2
lines changed

2 files changed

+24
-2
lines changed

src/Compiler.php

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,9 @@ public function convertNode(DOMNode $node, int $level = 0): DOMNode
190190
} elseif ($node instanceof DOMDocument) {
191191
$this->logger->warning('Document node found.');
192192
} elseif ($node instanceof DOMElement) {
193-
$this->twigRemove($node);
193+
if ($this->twigRemove($node)) {
194+
return $node;
195+
}
194196
$this->replaceShowWithIf($node);
195197
$this->handleIf($node, $level);
196198
$this->handleFor($node);
@@ -976,10 +978,14 @@ private function handleCommentNode(DOMComment $node): void
976978
}
977979
}
978980

979-
private function twigRemove(DOMElement $node): void
981+
private function twigRemove(DOMElement $node): bool
980982
{
981983
if ($node->hasAttribute('data-twig-remove')) {
982984
$node->parentNode->removeChild($node);
985+
986+
return true;
983987
}
988+
989+
return false;
984990
}
985991
}

tests/DataTwigRemoveTest.php

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,4 +21,20 @@ public function testDataTwigRemove()
2121

2222
$this->assertEqualHtml($expected, $actual);
2323
}
24+
25+
/**
26+
* @throws Exception
27+
*/
28+
public function testDataTwigRemoveWithIf()
29+
{
30+
$vueTemplate = '<template><div><span v-if="true" data-twig-remove>dummy</span></div></template>';
31+
32+
$expected = '<div class="{{ class|default(\'\') }}" style="{{ style|default(\'\') }}"></div>';
33+
34+
$compiler = $this->createCompiler($vueTemplate);
35+
36+
$actual = $compiler->convert();
37+
38+
$this->assertEqualHtml($expected, $actual);
39+
}
2440
}

0 commit comments

Comments
 (0)