[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
@@ -23,8 +23,8 @@ exports[`lifecycle hooks component semantics 1`] = `
let block1 = createBlock(\`<div>A<block-child-0/><block-child-1/></div>\`);
return function template(ctx, node, key = \\"\\") {
const b2 = comp1({}, key + \`__1\`, node, ctx, null);
const b3 = comp2({}, key + \`__2\`, node, ctx, null);
const b2 = comp1({}, key + \`__1\`, node, this, null);
const b3 = comp2({}, key + \`__2\`, node, this, null);
return block1([], [b2, b3]);
}
}"
@@ -55,11 +55,11 @@ exports[`lifecycle hooks component semantics 3`] = `
return function template(ctx, node, key = \\"\\") {
let b2,b3,b4;
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);
} else {
b4 = comp3({}, key + \`__3\`, node, ctx, null);
b4 = comp3({}, key + \`__3\`, node, this, null);
}
return block1([], [b2, b3, b4]);
}
@@ -116,7 +116,7 @@ exports[`lifecycle hooks components are unmounted and destroyed if no longer in
return function template(ctx, node, key = \\"\\") {
let b2;
if (ctx['state'].flag) {
const b3 = comp1({n: ctx['state'].n}, key + \`__1\`, node, ctx, null);
const b3 = comp1({n: ctx['state'].n}, key + \`__1\`, node, this, null);
b2 = block2([], [b3]);
}
return multi([b2]);
@@ -147,7 +147,7 @@ exports[`lifecycle hooks components are unmounted destroyed if no longer in DOM
return function template(ctx, node, key = \\"\\") {
let b2;
if (ctx['state'].ok) {
b2 = comp1({}, key + \`__1\`, node, ctx, null);
b2 = comp1({}, key + \`__1\`, node, this, null);
}
return multi([b2]);
}
@@ -177,7 +177,7 @@ exports[`lifecycle hooks destroy new children before being mountged 1`] = `
let b2,b3,b4;
b2 = text(\`before\`);
if (ctx['state'].flag) {
b3 = comp1({}, key + \`__1\`, node, ctx, null);
b3 = comp1({}, key + \`__1\`, node, this, null);
}
b4 = text(\`after\`);
return multi([b2, b3, b4]);
@@ -205,7 +205,7 @@ exports[`lifecycle hooks hooks are called in proper order in widget creation/des
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]);
}
}"
@@ -231,7 +231,7 @@ exports[`lifecycle hooks lifecycle callbacks are bound to component 1`] = `
const comp1 = app.createComponent(\`Test\`, true, false, false, false);
return function template(ctx, node, key = \\"\\") {
return comp1({rev: ctx['rev']}, key + \`__1\`, node, ctx, null);
return comp1({rev: ctx['rev']}, key + \`__1\`, node, this, null);
}
}"
`;
@@ -256,7 +256,7 @@ exports[`lifecycle hooks lifecycle semantics 1`] = `
let block1 = createBlock(\`<div><block-child-0/></div>\`);
return function template(ctx, node, key = \\"\\") {
const b2 = comp1({a: ctx['state'].a}, key + \`__1\`, node, ctx, null);
const b2 = comp1({a: ctx['state'].a}, key + \`__1\`, node, this, null);
return block1([], [b2]);
}
}"
@@ -284,7 +284,7 @@ exports[`lifecycle hooks lifecycle semantics, part 2 1`] = `
return function template(ctx, node, key = \\"\\") {
let b2;
if (ctx['state'].hasChild) {
b2 = comp1({}, key + \`__1\`, node, ctx, null);
b2 = comp1({}, key + \`__1\`, node, this, null);
}
return multi([b2]);
}
@@ -298,7 +298,7 @@ exports[`lifecycle hooks lifecycle semantics, part 2 2`] = `
const comp1 = app.createComponent(\`GrandChild\`, true, false, false, true);
return function template(ctx, node, key = \\"\\") {
return comp1({}, key + \`__1\`, node, ctx, null);
return comp1({}, key + \`__1\`, node, this, null);
}
}"
`;
@@ -325,7 +325,7 @@ exports[`lifecycle hooks lifecycle semantics, part 3 1`] = `
return function template(ctx, node, key = \\"\\") {
let b2;
if (ctx['state'].hasChild) {
b2 = comp1({}, key + \`__1\`, node, ctx, null);
b2 = comp1({}, key + \`__1\`, node, this, null);
}
return multi([b2]);
}
@@ -341,7 +341,7 @@ exports[`lifecycle hooks lifecycle semantics, part 4 1`] = `
return function template(ctx, node, key = \\"\\") {
let b2;
if (ctx['state'].hasChild) {
b2 = comp1({}, key + \`__1\`, node, ctx, null);
b2 = comp1({}, key + \`__1\`, node, this, null);
}
return multi([b2]);
}
@@ -355,7 +355,7 @@ exports[`lifecycle hooks lifecycle semantics, part 4 2`] = `
const comp1 = app.createComponent(\`GrandChild\`, true, false, false, true);
return function template(ctx, node, key = \\"\\") {
return comp1({}, key + \`__1\`, node, ctx, null);
return comp1({}, key + \`__1\`, node, this, null);
}
}"
`;
@@ -382,7 +382,7 @@ exports[`lifecycle hooks lifecycle semantics, part 5 1`] = `
return function template(ctx, node, key = \\"\\") {
let b2;
if (ctx['state'].hasChild) {
b2 = comp1({}, key + \`__1\`, node, ctx, null);
b2 = comp1({}, key + \`__1\`, node, this, null);
}
return multi([b2]);
}
@@ -409,7 +409,7 @@ exports[`lifecycle hooks lifecycle semantics, part 6 1`] = `
const comp1 = app.createComponent(\`Child\`, true, false, false, false);
return function template(ctx, node, key = \\"\\") {
return comp1({value: ctx['state'].value}, key + \`__1\`, node, ctx, null);
return comp1({value: ctx['state'].value}, key + \`__1\`, node, this, null);
}
}"
`;
@@ -449,7 +449,7 @@ exports[`lifecycle hooks mounted hook is called on every mount, not just the fir
return function template(ctx, node, key = \\"\\") {
let b2;
if (ctx['state'].hasChild) {
b2 = comp1({}, key + \`__1\`, node, ctx, null);
b2 = comp1({}, key + \`__1\`, node, this, null);
}
return multi([b2]);
}
@@ -478,7 +478,7 @@ exports[`lifecycle hooks mounted hook is called on subcomponents, in proper orde
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]);
}
}"
@@ -508,7 +508,7 @@ exports[`lifecycle hooks mounted hook is called on subsubcomponents, in proper o
return function template(ctx, node, key = \\"\\") {
let b2;
if (ctx['state'].flag) {
b2 = comp1({}, key + \`__1\`, node, ctx, null);
b2 = comp1({}, key + \`__1\`, node, this, null);
}
return block1([], [b2]);
}
@@ -524,7 +524,7 @@ exports[`lifecycle hooks mounted hook is called on subsubcomponents, in proper o
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]);
}
}"
@@ -550,7 +550,7 @@ exports[`lifecycle hooks onWillRender 1`] = `
const comp1 = app.createComponent(\`Child\`, true, false, false, false);
return function template(ctx, node, key = \\"\\") {
return comp1({someValue: ctx['state'].value}, key + \`__1\`, node, ctx, null);
return comp1({someValue: ctx['state'].value}, key + \`__1\`, node, this, null);
}
}"
`;
@@ -579,7 +579,7 @@ exports[`lifecycle hooks patched hook is called after updateProps 1`] = `
let block1 = createBlock(\`<div><block-child-0/></div>\`);
return function template(ctx, node, key = \\"\\") {
const b2 = comp1({a: ctx['state'].a}, key + \`__1\`, node, ctx, null);
const b2 = comp1({a: ctx['state'].a}, key + \`__1\`, node, this, null);
return block1([], [b2]);
}
}"
@@ -663,7 +663,7 @@ exports[`lifecycle hooks sub widget (inside sub node): hooks are correctly calle
return function template(ctx, node, key = \\"\\") {
let b2;
if (ctx['state'].flag) {
b2 = comp1({}, key + \`__1\`, node, ctx, null);
b2 = comp1({}, key + \`__1\`, node, this, null);
}
return multi([b2]);
}
@@ -705,7 +705,7 @@ exports[`lifecycle hooks timeout in onWillUpdateProps emits a warning 1`] = `
return function template(ctx, node, key = \\"\\") {
const props1 = {prop: ctx['state'].prop};
helpers.validateProps(\`Child\`, props1, ctx);
return comp1(props1, key + \`__1\`, node, ctx, null);
return comp1(props1, key + \`__1\`, node, this, null);
}
}"
`;
@@ -730,7 +730,7 @@ exports[`lifecycle hooks willPatch, patched hook are called on subsubcomponents,
let block1 = createBlock(\`<div><block-child-0/></div>\`);
return function template(ctx, node, key = \\"\\") {
const b2 = comp1({n: ctx['state'].n}, key + \`__1\`, node, ctx, null);
const b2 = comp1({n: ctx['state'].n}, key + \`__1\`, node, this, null);
return block1([], [b2]);
}
}"
@@ -745,7 +745,7 @@ exports[`lifecycle hooks willPatch, patched hook are called on subsubcomponents,
let block1 = createBlock(\`<div><block-child-0/></div>\`);
return function template(ctx, node, key = \\"\\") {
const b2 = comp1({n: ctx['props'].n}, key + \`__1\`, node, ctx, null);
const b2 = comp1({n: ctx['props'].n}, key + \`__1\`, node, this, null);
return block1([], [b2]);
}
}"
@@ -772,7 +772,7 @@ exports[`lifecycle hooks willStart hook is called on sub component 1`] = `
const comp1 = app.createComponent(\`Child\`, true, false, false, true);
return function template(ctx, node, key = \\"\\") {
return comp1({}, key + \`__1\`, node, ctx, null);
return comp1({}, key + \`__1\`, node, this, null);
}
}"
`;
@@ -828,7 +828,7 @@ exports[`lifecycle hooks willStart, mounted on subwidget rendered after main is
return function template(ctx, node, key = \\"\\") {
let b2,b3;
if (ctx['state'].ok) {
b2 = comp1({}, key + \`__1\`, node, ctx, null);
b2 = comp1({}, key + \`__1\`, node, this, null);
} else {
b3 = block3();
}
@@ -857,7 +857,7 @@ exports[`lifecycle hooks willUpdateProps hook is called 1`] = `
const comp1 = app.createComponent(\`Child\`, true, false, false, false);
return function template(ctx, node, key = \\"\\") {
return comp1({n: ctx['state'].n}, key + \`__1\`, node, ctx, null);
return comp1({n: ctx['state'].n}, key + \`__1\`, node, this, null);
}
}"
`;