Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 11 additions & 6 deletions src/Compiler.php
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,6 @@ public function convertNode(DOMNode $node, int $level = 0): DOMNode
$this->handleIf($node);
$this->handleFor($node);
$this->stripEventHandlers($node);
//$this->handleRawHtml($node, $data);
$this->handleDefaultSlot($node);
$this->cleanupAttributes($node);
}
Expand Down Expand Up @@ -410,14 +409,20 @@ protected function handleTextNode(DOMText $node)
}

private function cleanupAttributes(DOMElement $node) {
if ($node->hasAttribute('ref')) {
$node->removeAttribute('ref');
$removeAttributes = [];
/** @var DOMAttr $attribute */
foreach ($node->attributes as $attribute) {
if (
(preg_match('/^v-([a-z]*)/', $attribute->name, $matches) === 1 && $matches[1] !== 'bind')
|| preg_match('/^[:]?ref$/', $attribute->name) === 1
) {
$removeAttributes[] = $attribute->name;
}
}
if ($node->hasAttribute(':ref')) {
$node->removeAttribute(':ref');
foreach ($removeAttributes as $removeAttribute) {
$node->removeAttribute($removeAttribute);
}
}

private function handleIf(DOMElement $node): void
{
if (!$node->hasAttribute('v-if') &&
Expand Down
2 changes: 1 addition & 1 deletion tests/CleanupAttributesTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ class CleanupAttributesTest extends AbstractTestCase
{
public function testCleanupAttributes()
{
$vueTemplate = '<template><div ref="reference">dummy</div></template>';
$vueTemplate = '<template><div v-foo="bar" ref="reference">dummy</div></template>';

$expected = '<div class="{{class|default(\'\')}}">dummy</div>';

Expand Down
2 changes: 1 addition & 1 deletion tests/fixtures/vue-bind/bindings.vue
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<div>
<div>
<input type="radio" :checked="true">
<img :src="imageSrc">
<img v-bind:src="imageSrc">
<img :src="imageSrc">
<div :class="['a', 'b', 'c']"></div>
<div title="Title" :class="{ 'block': isSomething, 'block2': !isSomething}" class="category-filter-list categories"></div>
Expand Down