From d917a6cc3eaf2f940e9844aba9326965c2dc28d9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Stefan=20H=C3=BCsges?= Date: Mon, 10 Feb 2020 18:13:27 +0100 Subject: [PATCH 1/4] Add handleCommentNode --- src/Compiler.php | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/src/Compiler.php b/src/Compiler.php index 6b8c33d..d75d0c6 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,14 @@ protected function handleRootNodeClassAttribute($node) { $node->setAttributeNode($attributeVClass); return $node; } + + private function handleCommentNode(DOMComment $node) + { + if ( + stripos($node->nodeValue, 'eslint-disable') !== false + || stripos($node->nodeValue, 'todo') !== false + ) { + $node->deleteData(0, $node->length); + } + } } From 7b21fac3065d2a085c0944380e0e3d8e52edc79a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Stefan=20H=C3=BCsges?= Date: Fri, 14 Feb 2020 11:31:36 +0100 Subject: [PATCH 2/4] Update handleCommentNode --- src/Compiler.php | 8 +++----- tests/CommentNodeTest.php | 42 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 45 insertions(+), 5 deletions(-) create mode 100644 tests/CommentNodeTest.php diff --git a/src/Compiler.php b/src/Compiler.php index d75d0c6..cf8a615 100644 --- a/src/Compiler.php +++ b/src/Compiler.php @@ -754,11 +754,9 @@ protected function handleRootNodeClassAttribute($node) { private function handleCommentNode(DOMComment $node) { - if ( - stripos($node->nodeValue, 'eslint-disable') !== false - || stripos($node->nodeValue, 'todo') !== false - ) { - $node->deleteData(0, $node->length); + $nodeValue = trim($node->nodeValue); + if (stripos($nodeValue, 'eslint-disable') === 0 || stripos($nodeValue, 'todo') === 0) { + $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); + } +} From fae2d033f4065d00e680ab0acda00df30d2bd437 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Stefan=20H=C3=BCsges?= Date: Mon, 17 Feb 2020 07:03:22 +0100 Subject: [PATCH 3/4] Update handleCommentNode --- src/Compiler.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Compiler.php b/src/Compiler.php index cf8a615..c31a2c7 100644 --- a/src/Compiler.php +++ b/src/Compiler.php @@ -755,7 +755,7 @@ protected function handleRootNodeClassAttribute($node) { private function handleCommentNode(DOMComment $node) { $nodeValue = trim($node->nodeValue); - if (stripos($nodeValue, 'eslint-disable') === 0 || stripos($nodeValue, 'todo') === 0) { + if (preg_match('/^(eslint-disable|@?todo)/', $nodeValue) === 1) { $node->parentNode->removeChild($node); } } From 0ceb2c6737baeabd6a3bca1db14cc826096d664f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Stefan=20H=C3=BCsges?= Date: Mon, 17 Feb 2020 07:12:34 +0100 Subject: [PATCH 4/4] Update handleCommentNode --- src/Compiler.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Compiler.php b/src/Compiler.php index c31a2c7..e177910 100644 --- a/src/Compiler.php +++ b/src/Compiler.php @@ -755,7 +755,7 @@ protected function handleRootNodeClassAttribute($node) { private function handleCommentNode(DOMComment $node) { $nodeValue = trim($node->nodeValue); - if (preg_match('/^(eslint-disable|@?todo)/', $nodeValue) === 1) { + if (preg_match('/^(eslint-disable|@?todo)/i', $nodeValue) === 1) { $node->parentNode->removeChild($node); } }