diff --git a/src/compiler/parser.ts b/src/compiler/parser.ts index 4f3f39f7..0bf572d9 100644 --- a/src/compiler/parser.ts +++ b/src/compiler/parser.ts @@ -781,8 +781,9 @@ function parseComponent(node: Element, ctx: ParsingContext): AST | null { // default slot const defaultContent = parseChildNodes(clone, ctx); - if (defaultContent) { - slots = slots || {}; + slots = slots || {}; + // t-set-slot="default" has priority over content + if (defaultContent && !slots.default) { slots.default = { content: defaultContent, on, attrs: null, scope: defaultSlotScope }; } } diff --git a/tests/components/__snapshots__/slots.test.ts.snap b/tests/components/__snapshots__/slots.test.ts.snap index 4930b7d1..e2165068 100644 --- a/tests/components/__snapshots__/slots.test.ts.snap +++ b/tests/components/__snapshots__/slots.test.ts.snap @@ -2835,6 +2835,36 @@ exports[`slots t-set t-value in a slot 2`] = ` }" `; +exports[`slots t-set-slot=default has priority over rest of the content 1`] = ` +"function anonymous(app, bdom, helpers +) { + let { text, createBlock, list, multi, html, toggler, comment } = bdom; + let { capture, markRaw } = helpers; + const comp1 = app.createComponent(\`Child\`, true, true, false, true); + + function slot1(ctx, node, key = \\"\\") { + return text(\`some other text\`); + } + + return function template(ctx, node, key = \\"\\") { + const ctx1 = capture(ctx); + return comp1({slots: markRaw({'default': {__render: slot1, __ctx: ctx1}})}, key + \`__1\`, node, this, null); + } +}" +`; + +exports[`slots t-set-slot=default has priority over rest of the content 2`] = ` +"function anonymous(app, bdom, helpers +) { + let { text, createBlock, list, multi, html, toggler, comment } = bdom; + let { callSlot } = helpers; + + return function template(ctx, node, key = \\"\\") { + return callSlot(ctx, node, key, 'default', false, {}); + } +}" +`; + exports[`slots t-slot in recursive templates 1`] = ` "function anonymous(app, bdom, helpers ) { diff --git a/tests/components/slots.test.ts b/tests/components/slots.test.ts index 9373bf2d..f36ef6d0 100644 --- a/tests/components/slots.test.ts +++ b/tests/components/slots.test.ts @@ -45,6 +45,23 @@ describe("slots", () => { expect(fixture.innerHTML).toBe("some text"); }); + test("t-set-slot=default has priority over rest of the content", async () => { + class Child extends Component { + static template = xml``; + } + + class Parent extends Component { + static template = xml` + some text + some other text + `; + static components = { Child }; + } + await mount(Parent, fixture); + + expect(fixture.innerHTML).toBe("some other text"); + }); + test("simple slot with slot scope", async () => { let child: any; class Child extends Component {