From c9910077a488aa2aebf20ba2589fea25d3a20e8c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?G=C3=A9ry=20Debongnie?= Date: Thu, 12 Sep 2019 23:22:55 +0200 Subject: [PATCH] [FIX] qweb: do not capture current qweb instance in closure it is not needed, and has a bad effect on globally registered templates. --- src/qweb/qweb.ts | 2 +- tests/qweb/__snapshots__/qweb.test.ts.snap | 15 +++++++++++++++ tests/qweb/qweb.test.ts | 8 ++++++++ 3 files changed, 24 insertions(+), 1 deletion(-) diff --git a/src/qweb/qweb.ts b/src/qweb/qweb.ts index 48a11528..e0c49809 100644 --- a/src/qweb/qweb.ts +++ b/src/qweb/qweb.ts @@ -241,7 +241,7 @@ export class QWeb extends EventBus { this._processTemplate(elem); const template = { elem, - fn: (context, extra) => { + fn: function (this: QWeb, context, extra) { const compiledFunction = this._compile(name, elem); template.fn = compiledFunction; return compiledFunction.call(this, context, extra); diff --git a/tests/qweb/__snapshots__/qweb.test.ts.snap b/tests/qweb/__snapshots__/qweb.test.ts.snap index 1686d252..480a62e6 100644 --- a/tests/qweb/__snapshots__/qweb.test.ts.snap +++ b/tests/qweb/__snapshots__/qweb.test.ts.snap @@ -1118,6 +1118,21 @@ exports[`t-call (template calling t-call with t-if 1`] = ` }" `; +exports[`t-call (template calling t-call, global templates 1`] = ` +"function anonymous(context,extra +) { + var h = this.h; + let c1 = [], p1 = {key:1}; + var vn1 = h('div', p1, c1); + result = vn1; + let c2 = [], p2 = {key:2}; + var vn2 = h('span', p2, c2); + c1.push(vn2); + c2.push({text: \`desk\`}); + return vn1; +}" +`; + exports[`t-call (template calling with unused body 1`] = ` "function anonymous(context,extra ) { diff --git a/tests/qweb/qweb.test.ts b/tests/qweb/qweb.test.ts index b21fa4ae..577f2b59 100644 --- a/tests/qweb/qweb.test.ts +++ b/tests/qweb/qweb.test.ts @@ -662,6 +662,14 @@ describe("t-call (template calling", () => { const recursiveFn = Object.values(qweb.recursiveFns)[0]; expect(recursiveFn.toString()).toMatchSnapshot(); }); + + test("t-call, global templates", () => { + QWeb.registerTemplate('abcd', '
') + qweb.addTemplate("john", `desk`); + const expected = "
desk
"; + expect(trim(renderToString(qweb, "abcd"))).toBe(expected); + }); + }); describe("foreach", () => {