[FIX] compiler: do not look up ComponentNode in the context

With the introduction of t-call-context, there is now no guarantee that
the ComponentNode can be found in the rendering context, any attempt to
do so can crash when combined with t-call-context. This commit fixes
that by using `this` instead, which in compiled templates refers to the
component that is being rendered.
This commit is contained in:
Samuel Degueldre
2022-11-18 10:13:57 +01:00
committed by Géry Debongnie
parent 3d49daedcd
commit 9a5edb4590
18 changed files with 337 additions and 234 deletions
@@ -217,7 +217,7 @@ exports[`misc other complex template 1`] = `
let block25 = createBlock(\`<div><block-child-0/><block-child-1/></div>\`);
return function template(ctx, node, key = \\"\\") {
const refs = ctx.__owl__.refs;
const refs = this.__owl__.refs;
const ref1 = (el) => refs[\`search_input\`] = el;
const ref2 = (el) => refs[\`settings_menu\`] = el;
let b2,b4,b14,b17,b22,b23,b24,b25;
@@ -8,7 +8,7 @@ exports[`t-ref can get a dynamic ref on a node 1`] = `
let block1 = createBlock(\`<div><span block-ref=\\"0\\"/></div>\`);
return function template(ctx, node, key = \\"\\") {
const refs = ctx.__owl__.refs;
const refs = this.__owl__.refs;
const v1 = ctx['id'];
let ref1 = (el) => refs[\`myspan\${v1}\`] = el;
return block1([ref1]);
@@ -24,7 +24,7 @@ exports[`t-ref can get a dynamic ref on a node, alternate syntax 1`] = `
let block1 = createBlock(\`<div><span block-ref=\\"0\\"/></div>\`);
return function template(ctx, node, key = \\"\\") {
const refs = ctx.__owl__.refs;
const refs = this.__owl__.refs;
const v1 = ctx['id'];
let ref1 = (el) => refs[\`myspan\${v1}\`] = el;
return block1([ref1]);
@@ -40,7 +40,7 @@ exports[`t-ref can get a ref on a node 1`] = `
let block1 = createBlock(\`<div><span block-ref=\\"0\\"/></div>\`);
return function template(ctx, node, key = \\"\\") {
const refs = ctx.__owl__.refs;
const refs = this.__owl__.refs;
const ref1 = (el) => refs[\`myspan\`] = el;
return block1([ref1]);
}
@@ -70,7 +70,7 @@ exports[`t-ref ref in a t-call 2`] = `
let block1 = createBlock(\`<div>1<span block-ref=\\"0\\"/>2</div>\`);
return function template(ctx, node, key = \\"\\") {
const refs = ctx.__owl__.refs;
const refs = this.__owl__.refs;
const ref1 = (el) => refs[\`name\`] = el;
return block1([ref1]);
}
@@ -86,7 +86,7 @@ exports[`t-ref ref in a t-if 1`] = `
let block2 = createBlock(\`<span block-ref=\\"0\\"/>\`);
return function template(ctx, node, key = \\"\\") {
const refs = ctx.__owl__.refs;
const refs = this.__owl__.refs;
const ref1 = (el) => refs[\`name\`] = el;
let b2;
if (ctx['condition']) {
@@ -107,7 +107,7 @@ exports[`t-ref refs in a loop 1`] = `
let block3 = createBlock(\`<div block-ref=\\"0\\"><block-text-1/></div>\`);
return function template(ctx, node, key = \\"\\") {
const refs = ctx.__owl__.refs;
const refs = this.__owl__.refs;
ctx = Object.create(ctx);
const [k_block2, v_block2, l_block2, c_block2] = prepareList(ctx['items']);;
for (let i1 = 0; i1 < l_block2; i1++) {
@@ -134,7 +134,7 @@ exports[`t-ref two refs, one in a t-if 1`] = `
let block2 = createBlock(\`<span block-ref=\\"0\\"/>\`);
return function template(ctx, node, key = \\"\\") {
const refs = ctx.__owl__.refs;
const refs = this.__owl__.refs;
const ref1 = (el) => refs[\`name\`] = el;
const ref2 = (el) => refs[\`p\`] = el;
let b2;
+2 -1
View File
@@ -114,7 +114,8 @@ describe("t-ref", () => {
app.addTemplate("main", main);
app.addTemplate("sub", sub);
const bdom = app.getTemplate("main")({ __owl__: { refs } }, {});
const comp = { __owl__: { refs } };
const bdom = app.getTemplate("main").call(comp, comp, {});
mount(bdom, document.createElement("div"));
expect(refs.name.tagName).toBe("SPAN");