mirror of
https://github.com/odoo/owl.git
synced 2025-10-06 19:59:41 +07:00
[FIX] qweb: do not capture current qweb instance in closure
it is not needed, and has a bad effect on globally registered templates.
This commit is contained in:
+1
-1
@@ -241,7 +241,7 @@ export class QWeb extends EventBus {
|
|||||||
this._processTemplate(elem);
|
this._processTemplate(elem);
|
||||||
const template = {
|
const template = {
|
||||||
elem,
|
elem,
|
||||||
fn: (context, extra) => {
|
fn: function (this: QWeb, context, extra) {
|
||||||
const compiledFunction = this._compile(name, elem);
|
const compiledFunction = this._compile(name, elem);
|
||||||
template.fn = compiledFunction;
|
template.fn = compiledFunction;
|
||||||
return compiledFunction.call(this, context, extra);
|
return compiledFunction.call(this, context, extra);
|
||||||
|
|||||||
@@ -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`] = `
|
exports[`t-call (template calling with unused body 1`] = `
|
||||||
"function anonymous(context,extra
|
"function anonymous(context,extra
|
||||||
) {
|
) {
|
||||||
|
|||||||
@@ -662,6 +662,14 @@ describe("t-call (template calling", () => {
|
|||||||
const recursiveFn = Object.values(qweb.recursiveFns)[0];
|
const recursiveFn = Object.values(qweb.recursiveFns)[0];
|
||||||
expect(recursiveFn.toString()).toMatchSnapshot();
|
expect(recursiveFn.toString()).toMatchSnapshot();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test("t-call, global templates", () => {
|
||||||
|
QWeb.registerTemplate('abcd', '<div><t t-call="john"/></div>')
|
||||||
|
qweb.addTemplate("john", `<span>desk</span>`);
|
||||||
|
const expected = "<div><span>desk</span></div>";
|
||||||
|
expect(trim(renderToString(qweb, "abcd"))).toBe(expected);
|
||||||
|
});
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
describe("foreach", () => {
|
describe("foreach", () => {
|
||||||
|
|||||||
Reference in New Issue
Block a user