Skip to content

Commit 5dd1533

Browse files
authored
Merge pull request #79 from tronsha/bugfix/slot_default
Fix for slot_default inheritance
2 parents 59888b6 + 6065217 commit 5dd1533

11 files changed

+35
-12
lines changed

src/Compiler.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -332,6 +332,8 @@ public function convertNode(DOMNode $node, int $level = 0): DOMNode
332332
if ($node->hasChildNodes() && !$usedComponent->hasSlot(Slot::SLOT_DEFAULT_NAME)) {
333333
$this->addSlot(Slot::SLOT_DEFAULT_NAME, $node, $usedComponent);
334334
}
335+
} else {
336+
$usedComponent->addEmptyDefaultSlot();
335337
}
336338

337339
// Include Partial

src/Models/Component.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,11 @@ public function addSlot(string $name, string $value): Slot
9090
return $this->slots[$name];
9191
}
9292

93+
public function addEmptyDefaultSlot(): void
94+
{
95+
$this->properties[] = new Property(Slot::SLOT_PREFIX . Slot::SLOT_DEFAULT_NAME, '""', false);
96+
}
97+
9398
public function kebabToCamelCase(string $string, bool $capitalizeFirstCharacter = false): string
9499
{
95100
$str = str_replace('-', '', ucwords($string, '-'));

tests/fixtures/style-block-scoped/style-block-scoped-with-child-binding.twig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,6 @@
55
</style>
66
<div class="root {{ class|default('') }}" data-v-7ac31a851ab0c4c52bc569b6f256bfe4 {{ dataScopedStyleAttribute|default('') }} style="{{ style|default('') }}">
77
<div class="foo" data-v-7ac31a851ab0c4c52bc569b6f256bfe4>
8-
{% include "/templates/ChildComponent.twig" with { 'dataScopedStyleAttribute': "data-v-7ac31a851ab0c4c52bc569b6f256bfe4", 'class': "", 'style': "" } %}
8+
{% include "/templates/ChildComponent.twig" with { 'slot_default': "", 'dataScopedStyleAttribute': "data-v-7ac31a851ab0c4c52bc569b6f256bfe4", 'class': "", 'style': "" } %}
99
</div>
1010
</div>
Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
<div class="{{ class|default('') }}" style="{{ style|default('') }}">
2-
{% include "/templates/ChildComponent.twig" with { 'test': "test", 'class': "", 'style': ( "fill:" ~ ( color ) ~ ";" ) } %}
3-
{% include "/templates/ChildComponent.twig" with { 'class': "", 'style': "color: red" ~ "; " ~ ( "fill:" ~ ( color ) ~ ";" ) } %}
4-
{% include "/templates/ChildComponent.twig" with { 'class': "foo" ~ " " ~ ( "bar" ), 'style': "" } %}
5-
{% include "/templates/ChildComponent.twig" with { 'class': "foo" ~ " " ~ ( bar ), 'style': "" } %}
6-
{% include "/templates/ChildComponent.twig" with { 'class': "product-column__tile" ~ " " ~ ( isSingleProductTile ? 'product-column__tile--large ' ), 'style': "" } %}
7-
{% include "/templates/ChildComponent.twig" with { 'ariaLabelledby': "foo-" ~ ( _uid ) ~ "", 'class': "", 'style': "" } %}
2+
{% include "/templates/ChildComponent.twig" with { 'test': "test", 'slot_default': "", 'class': "", 'style': ( "fill:" ~ ( color ) ~ ";" ) } %}
3+
{% include "/templates/ChildComponent.twig" with { 'slot_default': "", 'class': "", 'style': "color: red" ~ "; " ~ ( "fill:" ~ ( color ) ~ ";" ) } %}
4+
{% include "/templates/ChildComponent.twig" with { 'slot_default': "", 'class': "foo" ~ " " ~ ( "bar" ), 'style': "" } %}
5+
{% 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': "" } %}
7+
{% include "/templates/ChildComponent.twig" with { 'ariaLabelledby': "foo-" ~ ( _uid ) ~ "", 'slot_default': "", 'class': "", 'style': "" } %}
88
</div>
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
<div class="{{ class|default('') }}" style="{{ style|default('') }}">
2-
{% include "/templates/ChildComponent.twig" with { 'class': "", 'style': "" } %}
2+
{% include "/templates/ChildComponent.twig" with { 'slot_default': "", 'class': "", 'style': "" } %}
33
</div>
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
<div class="{{ class|default('') }}" style="{{ style|default('') }}">
2-
{% for a in listOfProducts %}{% include "/templates/ChildComponent.twig" with { 'string': "string", 'product': productA, 'class': "", 'style': "" } %}{% endfor %}
2+
{% for a in listOfProducts %}{% include "/templates/ChildComponent.twig" with { 'string': "string", 'product': productA, 'slot_default': "", 'class': "", 'style': "" } %}{% endfor %}
33
</div>
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
<div class="{{ class|default('') }}" style="{{ style|default('') }}">
2-
{% if a > 5 %}{% include "/templates/ChildComponent.twig" with { 'string': "string", 'product': productA, 'class': "", 'style': "" } %}{% endif %}
2+
{% if a > 5 %}{% include "/templates/ChildComponent.twig" with { 'string': "string", 'product': productA, 'slot_default': "", 'class': "", 'style': "" } %}{% endif %}
33
</div>

tests/fixtures/vue-component/component-with-inline-condition-prop.twig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,5 @@
22
{% include "/templates/ChildComponent.twig" with {
33
'product': testProduct,
44
'showSomething': index > 5 and a == true,
5-
'testA': "Hello", 'string': "Test", 'class': "", 'style': "" } %}
5+
'testA': "Hello", 'string': "Test", 'slot_default': "", 'class': "", 'style': "" } %}
66
</div>
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
<div class="{{ class|default('') }}" style="{{ style|default('') }}">
2-
{% include "/templates/ChildComponent.twig" with { 'product': testProduct, 'testA': "Hello", 'string': "Test", 'class': "", 'style': "" } %}
2+
{% include "/templates/ChildComponent.twig" with { 'product': testProduct, 'testA': "Hello", 'string': "Test", 'slot_default': "", 'class': "", 'style': "" } %}
33
</div>
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
<div class="{{ class|default('') }}" style="{{ style|default('') }}">
2+
{% include "/templates/ChildComponent.twig" with { 'slot_default': "", 'class': "", 'style': "" } %}
3+
</div>
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<template>
2+
<div>
3+
<ChildComponent />
4+
</div>
5+
</template>
6+
<script>
7+
export default {
8+
name: 'ComponentWithoutDefaultSlot',
9+
component: {
10+
ChildComponent,
11+
}
12+
};
13+
</script>

0 commit comments

Comments
 (0)