diff --git a/src/Compiler.php b/src/Compiler.php index 6b8c33d..e177910 100644 --- a/src/Compiler.php +++ b/src/Compiler.php @@ -137,6 +137,7 @@ public function convert(): string public function convertNode(DOMNode $node, int $level = 0): DOMNode { if($node instanceof DOMComment){ + $this->handleCommentNode($node); return $node; } elseif($node instanceof DOMText){ @@ -750,4 +751,12 @@ protected function handleRootNodeClassAttribute($node) { $node->setAttributeNode($attributeVClass); return $node; } + + private function handleCommentNode(DOMComment $node) + { + $nodeValue = trim($node->nodeValue); + if (preg_match('/^(eslint-disable|@?todo)/i', $nodeValue) === 1) { + $node->parentNode->removeChild($node); + } + } } diff --git a/tests/CommentNodeTest.php b/tests/CommentNodeTest.php new file mode 100644 index 0000000..7be76b5 --- /dev/null +++ b/tests/CommentNodeTest.php @@ -0,0 +1,42 @@ +
'; + $expected = ''; + + $compiler = $this->createCompiler($component); + + $actual = $compiler->convert(); + + $this->assertEqualHtml($expected, $actual); + } + + public function testCommentNodeEslintDisable() + { + $component = ''; + $expected = ''; + + $compiler = $this->createCompiler($component); + + $actual = $compiler->convert(); + + $this->assertEqualHtml($expected, $actual); + } + + public function testCommentNodeTodo() + { + $component = ''; + $expected = ''; + + $compiler = $this->createCompiler($component); + + $actual = $compiler->convert(); + + $this->assertEqualHtml($expected, $actual); + } +}