diff --git a/src/blockdom/multi.ts b/src/blockdom/multi.ts index a9a394c5..a7cf12fa 100644 --- a/src/blockdom/multi.ts +++ b/src/blockdom/multi.ts @@ -127,7 +127,7 @@ export class VMulti { } toString(): string { - return this.children.map((c) => c!.toString()).join(""); + return this.children.map((c) => (c ? c!.toString() : "")).join(""); } } diff --git a/tests/blockdom/multi.test.ts b/tests/blockdom/multi.test.ts index 2ec3a694..c02a889f 100644 --- a/tests/blockdom/multi.test.ts +++ b/tests/blockdom/multi.test.ts @@ -77,6 +77,11 @@ describe("multi blocks", () => { expect(fixture.innerHTML).toBe("ab"); }); + test("multi vnode can be used as text", () => { + mount(text(multi([text("a"), undefined]) as any), fixture); + expect(fixture.innerHTML).toBe("a"); + }); + test("multi inside a block", async () => { const block = createBlock("
"); const tree = block([], [multi([text("foo"), text("bar")])]); diff --git a/tests/compiler/__snapshots__/t_set.test.ts.snap b/tests/compiler/__snapshots__/t_set.test.ts.snap index 525bee84..72f3f9f4 100644 --- a/tests/compiler/__snapshots__/t_set.test.ts.snap +++ b/tests/compiler/__snapshots__/t_set.test.ts.snap @@ -87,6 +87,31 @@ exports[`t-set set from attribute lookup 1`] = ` }" `; +exports[`t-set set from body literal (with t-if/t-else 1`] = ` +"function anonymous(bdom, helpers +) { + let { text, createBlock, list, multi, html, toggler, component, comment } = bdom; + let { isBoundary, withDefault, LazyValue } = helpers; + + function value1(ctx, node, key = \\"\\") { + let b2,b3; + if (ctx['condition']) { + b2 = text(\`true\`); + } else { + b3 = text(\`false\`); + } + return multi([b2, b3]); + } + + return function template(ctx, node, key = \\"\\") { + ctx = Object.create(ctx); + ctx[isBoundary] = 1 + ctx[\`value\`] = new LazyValue(value1, ctx, node); + return text(ctx['value']); + } +}" +`; + exports[`t-set set from body literal 1`] = ` "function anonymous(bdom, helpers ) { diff --git a/tests/compiler/t_set.test.ts b/tests/compiler/t_set.test.ts index 540d7853..2c9cb162 100644 --- a/tests/compiler/t_set.test.ts +++ b/tests/compiler/t_set.test.ts @@ -38,6 +38,19 @@ describe("t-set", () => { expect(renderToString(template)).toBe("ok"); }); + test("set from body literal (with t-if/t-else", () => { + const template = ` + + + true + false + + + `; + expect(renderToString(template, { condition: true })).toBe("true"); + expect(renderToString(template, { condition: false })).toBe("false"); + }); + test("set from attribute lookup", () => { const template = `
`; expect(renderToString(template, { value: "ok" })).toBe("
ok
");