diff --git a/dom-bindings.d.ts b/dom-bindings.d.ts index 10030ec..7061d1f 100644 --- a/dom-bindings.d.ts +++ b/dom-bindings.d.ts @@ -89,7 +89,7 @@ export interface SimpleBindingData extends BaseBindingData { } export interface SlotBindingData extends BaseBindingData { - fallback?: TemplateChunk + template?: TemplateChunk } export interface TagBindingData extends BaseBindingData { diff --git a/src/bindings/slot.js b/src/bindings/slot.js index dbd9ad8..acb3460 100644 --- a/src/bindings/slot.js +++ b/src/bindings/slot.js @@ -28,7 +28,6 @@ export const SlotBinding = { // name: null, attributes: [], // template: null, - // fallback: null getTemplateScope(scope, parentScope) { return extendParentScope(this.attributes, scope, parentScope) @@ -42,13 +41,14 @@ export const SlotBinding = { const { parentNode } = this.node const realParent = getRealParent(scope, parentScope) + // override the template property if the slot needs to be replaced this.template = (templateData && template(templateData.html, templateData.bindings).createDOM( parentNode, )) || - // use the optional template fallback if provided by the compiler see also https://github.com/riot/riot/issues/3014 - this.fallback + // otherwise use the optional template fallback if provided by the compiler see also https://github.com/riot/riot/issues/3014 + this.template if (this.template) { cleanNode(this.node) @@ -107,11 +107,11 @@ function moveSlotInnerContent(slot) { * @param {AttributeExpressionData[]} attributes - slot attributes * @returns {Object} Slot binding object */ -export default function createSlot(node, { name, attributes, fallback }) { +export default function createSlot(node, { name, attributes, template }) { return { ...SlotBinding, attributes, - fallback, + template, node, name, } diff --git a/test/bindings/slot.spec.js b/test/bindings/slot.spec.js index 4644357..54b54d0 100644 --- a/test/bindings/slot.spec.js +++ b/test/bindings/slot.spec.js @@ -444,7 +444,7 @@ describe('slot bindings', () => { type: bindingTypes.SLOT, selector: '[expr0]', name: 'default', - fallback: template('

Default

'), + template: template('

Default

'), }, ])