Skip to content

Commit b433a72

Browse files
authored
Merge pull request #95 from tronsha/master
Fix binding with or in condition
2 parents 73545e5 + 5c6be8e commit b433a72

7 files changed

+40
-12
lines changed

src/Compiler.php

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -661,8 +661,7 @@ private function handleAttributeBinding(DOMElement $node): void
661661
}
662662

663663
$name = substr($attribute->name, strpos($attribute->name, ':') + 1);
664-
$value = $this->builder->sanitizeAttributeValue($attribute->value);
665-
$this->logger->debug('- handle: ' . $name . ' = ' . $value);
664+
$this->logger->debug('- handle: ' . $name . ' = ' . $attribute->value);
666665

667666
$staticValues = $node->hasAttribute($name) ? $node->getAttribute($name) : '';
668667

@@ -675,11 +674,11 @@ private function handleAttributeBinding(DOMElement $node): void
675674
}
676675

677676
// makes no sense to use this in code, but it must handled.
678-
if ($value === 'false') {
677+
if ($attribute->value === 'false') {
679678
continue;
680679
}
681680

682-
$dynamicValues = $this->handleBinding($value, $name, $node);
681+
$dynamicValues = $this->handleBinding($attribute->value, $name, $node);
683682

684683
$addIfAroundAttribute = in_array($name, $this->attributesWithIf);
685684

@@ -787,7 +786,7 @@ protected function handleObjectBinding(array $items, array &$dynamicValues, bool
787786
foreach ($items as $item) {
788787
if (preg_match($regexObjectElements, $item, $matchElement)) {
789788
$dynamicValues[] = $this->builder->prepareBindingOutput(
790-
$this->builder->refactorCondition($matchElement['condition']) . ' ? \'' . $matchElement['class'] . ' \'',
789+
$this->builder->refactorCondition($matchElement['condition']) . ' ? \'' . $matchElement['class'] . '\'',
791790
$twigOutput
792791
);
793792
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{% set foo = foo|default(false) %}
2+
{% set bar = bar|default(false) %}
3+
<div class="{{ class|default('') }}" style="{{ style|default('') }}">
4+
<div class="a {{ foo or bar ? 'b' }}">
5+
Foo
6+
</div>
7+
</div>
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
<template>
2+
<div>
3+
<div :class="['a', { 'b': foo || bar } ]">
4+
Foo
5+
</div>
6+
</div>
7+
</template>
8+
9+
<script>
10+
export default {
11+
props: {
12+
foo: {
13+
type: Boolean,
14+
default: false,
15+
},
16+
bar: {
17+
type: Boolean,
18+
default: false,
19+
},
20+
},
21+
};
22+
</script>
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{% set isDisabled = isDisabled|default(false) %}
22
<div class="{{ class|default('') }}" style="{{ style|default('') }}">
3-
<div class="a {{ isDisabled ? 'a--disabled ' }} b">
3+
<div class="a {{ isDisabled ? 'a--disabled' }} b">
44
Foo
55
</div>
66
</div>

tests/fixtures/vue-bind/bindings.twig

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,12 @@
44
<img src="{{ imageSrc }}">
55
<img src="{{ imageSrc }}">
66
<div class="a b c"></div>
7-
<div title="Title" class="category-filter-list categories {{ isSomething ? 'block ' }} {{ not isSomething ? 'block2 ' }}"></div>
7+
<div title="Title" class="category-filter-list categories {{ isSomething ? 'block' }} {{ not isSomething ? 'block2' }}"></div>
88
<div class="{{ getClasses(not hasSomething) }}"></div>
99
<div style="{{ 'display: none !important' }};">Hidden</div>
1010
<div style="color: red; {{ 'display: none !important' }};">Hidden</div>
11-
<div style="border: 1px solid #000000; {{ isSomething ? 'color: red ' }}; {{ not isSomething ? 'color: blue ' }};">Hidden</div>
12-
<div class="{{ bar ? 'foo ' }}"></div>
13-
<div class="{{ bar ? 'foo ' }}"></div>
11+
<div style="border: 1px solid #000000; {{ isSomething ? 'color: red' }}; {{ not isSomething ? 'color: blue' }};">Hidden</div>
12+
<div class="{{ bar ? 'foo' }}"></div>
13+
<div class="{{ bar ? 'foo' }}"></div>
1414
</div>
1515
</div>

tests/fixtures/vue-bind/double-attribute-binding.twig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
<div class="static1 static2 dynamic dynamic--{{ modifier }}">
33
Hello World
44
</div>
5-
<div class="static1 static2 {{ true ? 'my-class ' }}">
5+
<div class="static1 static2 {{ true ? 'my-class' }}">
66
With Object Binding
77
</div>
88
</div>

tests/fixtures/vue-component/component-with-child-binding.twig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,6 @@
33
{% include "/templates/ChildComponent.twig" with { 'slot_default': "", 'class': "", 'style': "color: red" ~ "; " ~ ( "fill:" ~ ( color ) ~ ";" ) } %}
44
{% include "/templates/ChildComponent.twig" with { 'slot_default': "", 'class': "foo" ~ " " ~ ( "bar" ), 'style': "" } %}
55
{% include "/templates/ChildComponent.twig" with { 'slot_default': "", 'class': "foo" ~ " " ~ ( bar ), 'style': "" } %}
6-
{% include "/templates/ChildComponent.twig" with { 'slot_default': "", 'class': "product-column__tile" ~ " " ~ ( isSingleProductTile ? 'product-column__tile--large ' ), 'style': "" } %}
6+
{% include "/templates/ChildComponent.twig" with { 'slot_default': "", 'class': "product-column__tile" ~ " " ~ ( isSingleProductTile ? 'product-column__tile--large' ), 'style': "" } %}
77
{% include "/templates/ChildComponent.twig" with { 'ariaLabelledby': "foo-" ~ ( _uid ) ~ "", 'slot_default': "", 'class': "", 'style': "" } %}
88
</div>

0 commit comments

Comments
 (0)