diff --git a/src/qweb/base_directives.ts b/src/qweb/base_directives.ts index 95c9a3cd..642a064b 100644 --- a/src/qweb/base_directives.ts +++ b/src/qweb/base_directives.ts @@ -223,9 +223,6 @@ QWeb.addDirective({ // ------------------------------------------------ ctx.rootContext.shouldDefineScope = true; ctx.rootContext.shouldDefineUtils = true; - if (node.nodeName !== "t") { - throw new Error("Invalid tag for t-call directive (should be 't')"); - } const subTemplate = node.getAttribute("t-call")!; const nodeTemplate = qweb.templates[subTemplate]; if (!nodeTemplate) { diff --git a/src/qweb/qweb.ts b/src/qweb/qweb.ts index 8cc81eb1..47289cee 100644 --- a/src/qweb/qweb.ts +++ b/src/qweb/qweb.ts @@ -517,10 +517,17 @@ export class QWeb extends EventBus { return; } + if (node.tagName !== "t" && node.hasAttribute("t-call")) { + const tCallNode = document.createElement("t"); + tCallNode.setAttribute("t-call", node.getAttribute("t-call")!); + node.removeAttribute("t-call"); + node.prepend(tCallNode); + } + const firstLetter = node.tagName[0]; if (firstLetter === firstLetter.toUpperCase()) { // this is a component, we modify in place the xml document to change - // to + // to node.setAttribute("t-component", node.tagName); } else if (node.tagName !== "t" && node.hasAttribute("t-component")) { throw new Error( diff --git a/tests/component/slots.test.ts b/tests/component/slots.test.ts index 59bca5af..cd5fa3cd 100644 --- a/tests/component/slots.test.ts +++ b/tests/component/slots.test.ts @@ -929,4 +929,62 @@ describe("t-slot directive", () => { expect(fixture.innerHTML).toBe("
dash
"); expect(env.qweb.templates[Dialog.template].fn.toString()).toMatchSnapshot(); }); + + test("slot and t-esc", async () => { + class Dialog extends Component { + static template = xml``; + } + class Parent extends Component { + static template = xml`
`; + static components = { Dialog }; + } + const parent = new Parent(); + await parent.mount(fixture); + + expect(fixture.innerHTML).toBe("
toph
"); + }); + + test("slot and (inline) t-esc", async () => { + class Dialog extends Component { + static template = xml``; + } + class Parent extends Component { + static template = xml`
`; + static components = { Dialog }; + } + const parent = new Parent(); + await parent.mount(fixture); + + expect(fixture.innerHTML).toBe("
toph
"); + }); + + test("slot and t-call", async () => { + env.qweb.addTemplate("sokka", "

sokka

"); + class Dialog extends Component { + static template = xml``; + } + class Parent extends Component { + static template = xml`
`; + static components = { Dialog }; + } + const parent = new Parent(); + await parent.mount(fixture); + + expect(fixture.innerHTML).toBe("

sokka

"); + }); + + test("slot and (inline) t-call", async () => { + env.qweb.addTemplate("sokka", "

sokka

"); + class Dialog extends Component { + static template = xml``; + } + class Parent extends Component { + static template = xml`
`; + static components = { Dialog }; + } + const parent = new Parent(); + await parent.mount(fixture); + + expect(fixture.innerHTML).toBe("

sokka

"); + }); }); diff --git a/tests/qweb/__snapshots__/qweb.test.ts.snap b/tests/qweb/__snapshots__/qweb.test.ts.snap index fc1fe3c9..e9e3f9df 100644 --- a/tests/qweb/__snapshots__/qweb.test.ts.snap +++ b/tests/qweb/__snapshots__/qweb.test.ts.snap @@ -1732,6 +1732,24 @@ exports[`t-call (template calling scoped parameters 1`] = ` }" `; +exports[`t-call (template calling t-call allowed on a non t node 1`] = ` +"function anonymous(context, extra +) { + // Template name: \\"caller\\" + let utils = this.constructor.utils; + let scope = Object.create(context); + let h = this.h; + let c1 = [], p1 = {key:1}; + let vn1 = h('div', p1, c1); + let _origScope3 = scope; + scope = Object.create(scope); + scope.__access_mode__ = 'ro'; + this.constructor.subTemplates['1'].call(this, scope, Object.assign({}, extra, {parentNode: c1, parent: utils.getComponent(context), key: '__4__'})); + scope = _origScope3; + return vn1; +}" +`; + exports[`t-call (template calling t-call with t-if 1`] = ` "function anonymous(context, extra ) { diff --git a/tests/qweb/qweb.test.ts b/tests/qweb/qweb.test.ts index cb468785..e4f0d734 100644 --- a/tests/qweb/qweb.test.ts +++ b/tests/qweb/qweb.test.ts @@ -766,10 +766,11 @@ describe("t-call (template calling", () => { expect(qweb.subTemplates["sub"]).toBeTruthy(); }); - test("t-call not allowed on a non t node", () => { - qweb.addTemplate("_basic-callee", "ok"); + test("t-call allowed on a non t node", () => { + qweb.addTemplate("_basic-callee", "ok"); qweb.addTemplate("caller", '
'); - expect(() => renderToString(qweb, "caller")).toThrow("Invalid tag"); + const expected = "
ok
"; + expect(renderToString(qweb, "caller")).toBe(expected); }); test("with unused body", () => {