[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[`style and class handling can set class on multi root component 1`] = `
const comp1 = app.createComponent(\`Child\`, true, false, false, false);
return function template(ctx, node, key = \\"\\") {
return comp1({class: 'fromparent'}, key + \`__1\`, node, ctx, null);
return comp1({class: 'fromparent'}, key + \`__1\`, node, this, null);
}
}"
`;
@@ -36,7 +36,7 @@ exports[`style and class handling can set class on sub component, as prop 1`] =
const comp1 = app.createComponent(\`Child\`, true, false, false, false);
return function template(ctx, node, key = \\"\\") {
return comp1({class: 'some-class'}, key + \`__1\`, node, ctx, null);
return comp1({class: 'some-class'}, key + \`__1\`, node, this, null);
}
}"
`;
@@ -62,7 +62,7 @@ exports[`style and class handling can set class on sub sub component 1`] = `
const comp1 = app.createComponent(\`Child\`, true, false, false, false);
return function template(ctx, node, key = \\"\\") {
return comp1({class: 'fromparent'}, key + \`__1\`, node, ctx, null);
return comp1({class: 'fromparent'}, key + \`__1\`, node, this, null);
}
}"
`;
@@ -74,7 +74,7 @@ exports[`style and class handling can set class on sub sub component 2`] = `
const comp1 = app.createComponent(\`ChildChild\`, true, false, false, false);
return function template(ctx, node, key = \\"\\") {
return comp1({class: (ctx['props'].class||'')+' fromchild'}, key + \`__1\`, node, ctx, null);
return comp1({class: (ctx['props'].class||'')+' fromchild'}, key + \`__1\`, node, this, null);
}
}"
`;
@@ -100,7 +100,7 @@ exports[`style and class handling can set more than one class on sub component 1
const comp1 = app.createComponent(\`Child\`, true, false, false, false);
return function template(ctx, node, key = \\"\\") {
return comp1({class: 'a b'}, key + \`__1\`, node, ctx, null);
return comp1({class: 'a b'}, key + \`__1\`, node, this, null);
}
}"
`;
@@ -153,7 +153,7 @@ exports[`style and class handling class on sub component, which is switched to a
const comp1 = app.createComponent(\`Child\`, true, false, false, false);
return function template(ctx, node, key = \\"\\") {
return comp1({class: 'someclass',child: ctx['state'].child}, key + \`__1\`, node, ctx, null);
return comp1({class: 'someclass',child: ctx['state'].child}, key + \`__1\`, node, this, null);
}
}"
`;
@@ -168,9 +168,9 @@ exports[`style and class handling class on sub component, which is switched to a
return function template(ctx, node, key = \\"\\") {
let b2,b3;
if (ctx['props'].child==='a') {
b2 = comp1({class: ctx['props'].class}, key + \`__1\`, node, ctx, null);
b2 = comp1({class: ctx['props'].class}, key + \`__1\`, node, this, null);
} else {
b3 = comp2({class: ctx['props'].class}, key + \`__2\`, node, ctx, null);
b3 = comp2({class: ctx['props'].class}, key + \`__2\`, node, this, null);
}
return multi([b2, b3]);
}
@@ -214,7 +214,7 @@ exports[`style and class handling class with extra whitespaces (variation) 1`] =
let block1 = createBlock(\`<p><block-child-0/></p>\`);
return function template(ctx, node, key = \\"\\") {
const b2 = comp1({class: 'a b c d'}, key + \`__1\`, node, ctx, null);
const b2 = comp1({class: 'a b c d'}, key + \`__1\`, node, this, null);
return block1([], [b2]);
}
}"
@@ -241,7 +241,7 @@ exports[`style and class handling class with extra whitespaces 1`] = `
const comp1 = app.createComponent(\`Child\`, true, false, false, false);
return function template(ctx, node, key = \\"\\") {
return comp1({class: 'a b c d'}, key + \`__1\`, node, ctx, null);
return comp1({class: 'a b c d'}, key + \`__1\`, node, this, null);
}
}"
`;
@@ -267,7 +267,7 @@ exports[`style and class handling component class and parent class combine toget
const comp1 = app.createComponent(\`Child\`, true, false, false, false);
return function template(ctx, node, key = \\"\\") {
return comp1({class: 'from parent'}, key + \`__1\`, node, ctx, null);
return comp1({class: 'from parent'}, key + \`__1\`, node, this, null);
}
}"
`;
@@ -322,7 +322,7 @@ exports[`style and class handling empty class attribute is not added on widget r
let block1 = createBlock(\`<div><block-child-0/></div>\`);
return function template(ctx, node, key = \\"\\") {
const b2 = comp1({class: undefined}, key + \`__1\`, node, ctx, null);
const b2 = comp1({class: undefined}, key + \`__1\`, node, this, null);
return block1([], [b2]);
}
}"
@@ -349,7 +349,7 @@ exports[`style and class handling error in subcomponent with class 1`] = `
const comp1 = app.createComponent(\`Child\`, true, false, false, false);
return function template(ctx, node, key = \\"\\") {
return comp1({class: 'a'}, key + \`__1\`, node, ctx, null);
return comp1({class: 'a'}, key + \`__1\`, node, this, null);
}
}"
`;
@@ -376,7 +376,7 @@ exports[`style and class handling no class is set is child ignores it 1`] = `
const comp1 = app.createComponent(\`Child\`, true, false, false, false);
return function template(ctx, node, key = \\"\\") {
return comp1({class: 'hey'}, key + \`__1\`, node, ctx, null);
return comp1({class: 'hey'}, key + \`__1\`, node, this, null);
}
}"
`;
@@ -401,7 +401,7 @@ exports[`style and class handling no class is set is parent does not give it as
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);
}
}"
`;
@@ -427,7 +427,7 @@ exports[`style and class handling style is properly added on widget root el 1`]
const comp1 = app.createComponent(\`Child\`, true, false, false, false);
return function template(ctx, node, key = \\"\\") {
return comp1({style: 'font-weight: bold;'}, key + \`__1\`, node, ctx, null);
return comp1({style: 'font-weight: bold;'}, key + \`__1\`, node, this, null);
}
}"
`;
@@ -455,7 +455,7 @@ exports[`style and class handling t-att-class is properly added/removed on widge
let block1 = createBlock(\`<div><block-child-0/></div>\`);
return function template(ctx, node, key = \\"\\") {
const b2 = comp1({class: {b:ctx['state'].b}}, key + \`__1\`, node, ctx, null);
const b2 = comp1({class: {b:ctx['state'].b}}, key + \`__1\`, node, this, null);
return block1([], [b2]);
}
}"
@@ -482,7 +482,7 @@ exports[`style and class handling t-att-class is properly added/removed on widge
const comp1 = app.createComponent(\`Child\`, true, false, false, false);
return function template(ctx, node, key = \\"\\") {
return comp1({class: {a:true,b:ctx['state'].b}}, key + \`__1\`, node, ctx, null);
return comp1({class: {a:true,b:ctx['state'].b}}, key + \`__1\`, node, this, null);
}
}"
`;