[FIX] properly get component reference instead of context

Before this commit, the generated code for the component directive was
using the current context as the place to look for static informations
(such as the sub components). However, it is not entirely correct, since
the current context may be different than the current component (which
is easily accessed by using the this variable).

Also, while doing this, we fix some issues in the t-set directive, which
as calling lazy values with the wrong this.
This commit is contained in:
Géry Debongnie
2022-06-22 15:39:31 +02:00
parent e57e2ee378
commit 5772b4e9e4
29 changed files with 528 additions and 526 deletions
@@ -7,7 +7,7 @@ exports[`basics basic use 1`] = `
const comp1 = app.createComponent(\`Child\`, true, false, false, false);
return function template(ctx, node, key = \\"\\") {
return comp1({p: 1}, key + \`__1\`, node, ctx, null);
return comp1({p: 1}, key + \`__1\`, node, this, null);
}
}"
`;
@@ -36,10 +36,10 @@ exports[`basics can select a sub widget 1`] = `
return function template(ctx, node, key = \\"\\") {
let b2,b3;
if (ctx['env'].options.flag) {
b2 = comp1({}, key + \`__1\`, node, ctx, null);
b2 = comp1({}, key + \`__1\`, node, this, null);
}
if (!ctx['env'].options.flag) {
b3 = comp2({}, key + \`__2\`, node, ctx, null);
b3 = comp2({}, key + \`__2\`, node, this, null);
}
return multi([b2, b3]);
}
@@ -82,10 +82,10 @@ exports[`basics can select a sub widget, part 2 1`] = `
return function template(ctx, node, key = \\"\\") {
let b2,b3;
if (ctx['state'].flag) {
b2 = comp1({}, key + \`__1\`, node, ctx, null);
b2 = comp1({}, key + \`__1\`, node, this, null);
}
if (!ctx['state'].flag) {
b3 = comp2({}, key + \`__2\`, node, ctx, null);
b3 = comp2({}, key + \`__2\`, node, this, null);
}
return multi([b2, b3]);
}
@@ -125,7 +125,7 @@ exports[`basics sub widget is interactive 1`] = `
const comp1 = app.createComponent(\`Child\`, true, false, false, false);
return function template(ctx, node, key = \\"\\") {
return comp1({p: 1}, key + \`__1\`, node, ctx, null);
return comp1({p: 1}, key + \`__1\`, node, this, null);
}
}"
`;
@@ -154,7 +154,7 @@ exports[`basics top level sub widget with a parent 1`] = `
let block1 = createBlock(\`<div><block-child-0/></div>\`);
return function template(ctx, node, key = \\"\\") {
const b2 = comp1({}, key + \`__1\`, node, ctx, null);
const b2 = comp1({}, key + \`__1\`, node, this, null);
return block1([], [b2]);
}
}"
@@ -167,7 +167,7 @@ exports[`basics top level sub widget with a parent 2`] = `
const comp1 = app.createComponent(\`ComponentC\`, true, false, false, true);
return function template(ctx, node, key = \\"\\") {
return comp1({}, key + \`__1\`, node, ctx, null);
return comp1({}, key + \`__1\`, node, this, null);
}
}"
`;