Skip to content

Commit 0f143fd

Browse files
committed
Merge remote-tracking branch 'origin/master' into feature/v-bind
# Conflicts: # src/Compiler.php
2 parents 36c9f6b + b6898f3 commit 0f143fd

File tree

3 files changed

+39
-2
lines changed

3 files changed

+39
-2
lines changed

src/Compiler.php

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,11 @@ class Compiler
121121
*/
122122
protected $attributesWithIf = ['checked', 'selected', 'disabled'];
123123

124+
/**
125+
* @var array
126+
*/
127+
protected $slotFallbackCounter = [];
128+
124129
/**
125130
* Compiler constructor.
126131
*/
@@ -1308,10 +1313,18 @@ protected function handleSlots(DOMElement $node): void
13081313
$slotName .= $node->getAttribute('name')
13091314
? str_replace('-', '_', $node->getAttribute('name'))
13101315
: Slot::SLOT_DEFAULT_NAME;
1316+
$slotFallbackKey = $slotName . '_fallback';
13111317

13121318
if ($slotFallback) {
1313-
$this->addVariable($slotName . '_fallback', $slotFallback);
1314-
$variable = $this->builder->createVariableOutput($slotName, $slotName . '_fallback');
1319+
if (isset($this->slotFallbackCounter[$slotFallbackKey])) {
1320+
++$this->slotFallbackCounter[$slotFallbackKey];
1321+
$slotFallbackName = $slotFallbackKey . '_' . $this->slotFallbackCounter[$slotFallbackKey];
1322+
} else {
1323+
$this->slotFallbackCounter[$slotFallbackKey] = 1;
1324+
$slotFallbackName = $slotFallbackKey;
1325+
}
1326+
$this->addVariable($slotFallbackName, $slotFallback);
1327+
$variable = $this->builder->createVariableOutput($slotName, $slotFallbackName);
13151328
} else {
13161329
$variable = $this->builder->createVariableOutput($slotName);
13171330
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
{% set slot_default_fallback %}{{ text }}{% endset %}
2+
{% set slot_default_fallback_2 %}{{ text }}{% endset %}
3+
{% if true %}
4+
<a href="#" class="{{ class|default('') }}" style="{{ style|default('') }}">
5+
{{ slot_default|default(slot_default_fallback) }}
6+
</a>
7+
{% else %}
8+
<button class="{{ class|default('') }}" style="{{ style|default('') }}">
9+
{{ slot_default|default(slot_default_fallback_2) }}
10+
</button>
11+
{% endif %}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<template>
2+
<a v-if="true" href="#">
3+
<slot>{{ text }}</slot>
4+
</a>
5+
<button v-else>
6+
<slot>{{ text }}</slot>
7+
</button>
8+
</template>
9+
<script>
10+
export default {
11+
name: 'ComponentWithTowDefaultSlots',
12+
};
13+
</script>

0 commit comments

Comments
 (0)