[IMP] qweb: re-add support of t-on directive

We add some test for the t-on directive.

For making them pass, it was necessary to change the code produced by
compileTForeach: the const declaration is not done by using generateId
and there was some conflict with the variable names produced in
captureExpression. Consequently, many snapshots had to be changed.

Code prettification has been done too.
This commit is contained in:
Mathieu Duckerts-Antoine
2021-10-15 13:08:07 +02:00
committed by Aaron Bohy
parent ee1ef20ce1
commit d6668e3439
16 changed files with 628 additions and 326 deletions
@@ -26,14 +26,14 @@ exports[`list of components components in a node in a t-foreach 2`] = `
return function template(ctx, node, key = \\"\\") {
ctx = Object.create(ctx);
const [k2, v2, l2, c2] = prepareList(ctx['items']);
for (let i1 = 0; i1 < l2; i1++) {
ctx[\`item\`] = v2[i1];
const [k_block2, v_block2, l_block2, c_block2] = prepareList(ctx['items']);
for (let i1 = 0; i1 < l_block2; i1++) {
ctx[\`item\`] = v_block2[i1];
let key1 = 'li_'+ctx['item'];
let b4 = component(\`Child\`, {item: ctx['item']}, key + \`__1__\${key1}\`, node, ctx);
c2[i1] = withKey(block3([], [b4]), key1);
c_block2[i1] = withKey(block3([], [b4]), key1);
}
let b2 = list(c2);
let b2 = list(c_block2);
return block1([], [b2]);
}
}"
@@ -64,14 +64,14 @@ exports[`list of components list of sub components inside other nodes 2`] = `
return function template(ctx, node, key = \\"\\") {
ctx = Object.create(ctx);
const [k2, v2, l2, c2] = prepareList(ctx['state'].blips);
for (let i1 = 0; i1 < l2; i1++) {
ctx[\`blip\`] = v2[i1];
const [k_block2, v_block2, l_block2, c_block2] = prepareList(ctx['state'].blips);
for (let i1 = 0; i1 < l_block2; i1++) {
ctx[\`blip\`] = v_block2[i1];
let key1 = ctx['blip'].id;
let b4 = component(\`SubComponent\`, {}, key + \`__1__\${key1}\`, node, ctx);
c2[i1] = withKey(block3([], [b4]), key1);
c_block2[i1] = withKey(block3([], [b4]), key1);
}
let b2 = list(c2);
let b2 = list(c_block2);
return block1([], [b2]);
}
}"
@@ -102,23 +102,23 @@ exports[`list of components reconciliation alg works for t-foreach in t-foreach
return function template(ctx, node, key = \\"\\") {
ctx = Object.create(ctx);
const [k2, v2, l2, c2] = prepareList(ctx['state'].s);
for (let i1 = 0; i1 < l2; i1++) {
ctx[\`section\`] = v2[i1];
const [k_block2, v_block2, l_block2, c_block2] = prepareList(ctx['state'].s);
for (let i1 = 0; i1 < l_block2; i1++) {
ctx[\`section\`] = v_block2[i1];
ctx[\`section_index\`] = i1;
let key1 = ctx['section_index'];
ctx = Object.create(ctx);
const [k3, v3, l3, c3] = prepareList(ctx['section'].blips);
for (let i2 = 0; i2 < l3; i2++) {
ctx[\`blip\`] = v3[i2];
const [k_block3, v_block3, l_block3, c_block3] = prepareList(ctx['section'].blips);
for (let i2 = 0; i2 < l_block3; i2++) {
ctx[\`blip\`] = v_block3[i2];
ctx[\`blip_index\`] = i2;
let key2 = ctx['blip_index'];
c3[i2] = withKey(component(\`Child\`, {blip: ctx['blip']}, key + \`__1__\${key1}__\${key2}\`, node, ctx), key2);
c_block3[i2] = withKey(component(\`Child\`, {blip: ctx['blip']}, key + \`__1__\${key1}__\${key2}\`, node, ctx), key2);
}
ctx = ctx.__proto__;
c2[i1] = withKey(list(c3), key1);
c_block2[i1] = withKey(list(c_block3), key1);
}
let b2 = list(c2);
let b2 = list(c_block2);
return block1([], [b2]);
}
}"
@@ -151,23 +151,23 @@ exports[`list of components reconciliation alg works for t-foreach in t-foreach,
return function template(ctx, node, key = \\"\\") {
ctx = Object.create(ctx);
const [k2, v2, l2, c2] = prepareList(ctx['state'].rows);
for (let i1 = 0; i1 < l2; i1++) {
ctx[\`row\`] = v2[i1];
const [k_block2, v_block2, l_block2, c_block2] = prepareList(ctx['state'].rows);
for (let i1 = 0; i1 < l_block2; i1++) {
ctx[\`row\`] = v_block2[i1];
let key1 = ctx['row'];
ctx = Object.create(ctx);
const [k4, v4, l4, c4] = prepareList(ctx['state'].cols);
for (let i2 = 0; i2 < l4; i2++) {
ctx[\`col\`] = v4[i2];
const [k_block4, v_block4, l_block4, c_block4] = prepareList(ctx['state'].cols);
for (let i2 = 0; i2 < l_block4; i2++) {
ctx[\`col\`] = v_block4[i2];
let key2 = ctx['col'];
let b6 = component(\`Child\`, {row: ctx['row'],col: ctx['col']}, key + \`__1__\${key1}__\${key2}\`, node, ctx);
c4[i2] = withKey(block5([], [b6]), key2);
c_block4[i2] = withKey(block5([], [b6]), key2);
}
ctx = ctx.__proto__;
let b4 = list(c4);
c2[i1] = withKey(block3([], [b4]), key1);
let b4 = list(c_block4);
c_block2[i1] = withKey(block3([], [b4]), key1);
}
let b2 = list(c2);
let b2 = list(c_block2);
return block1([], [b2]);
}
}"
@@ -196,13 +196,13 @@ exports[`list of components simple list 2`] = `
return function template(ctx, node, key = \\"\\") {
ctx = Object.create(ctx);
const [k1, v1, l1, c1] = prepareList(ctx['state'].elems);
for (let i1 = 0; i1 < l1; i1++) {
ctx[\`elem\`] = v1[i1];
const [k_block1, v_block1, l_block1, c_block1] = prepareList(ctx['state'].elems);
for (let i1 = 0; i1 < l_block1; i1++) {
ctx[\`elem\`] = v_block1[i1];
let key1 = ctx['elem'].id;
c1[i1] = withKey(component(\`Child\`, {value: ctx['elem'].value}, key + \`__1__\${key1}\`, node, ctx), key1);
c_block1[i1] = withKey(component(\`Child\`, {value: ctx['elem'].value}, key + \`__1__\${key1}\`, node, ctx), key1);
}
return list(c1);
return list(c_block1);
}
}"
`;
@@ -232,13 +232,13 @@ exports[`list of components sub components rendered in a loop 2`] = `
return function template(ctx, node, key = \\"\\") {
ctx = Object.create(ctx);
const [k2, v2, l2, c2] = prepareList(ctx['state'].numbers);
for (let i1 = 0; i1 < l2; i1++) {
ctx[\`number\`] = v2[i1];
const [k_block2, v_block2, l_block2, c_block2] = prepareList(ctx['state'].numbers);
for (let i1 = 0; i1 < l_block2; i1++) {
ctx[\`number\`] = v_block2[i1];
let key1 = ctx['number'];
c2[i1] = withKey(component(\`Child\`, {n: ctx['number']}, key + \`__1__\${key1}\`, node, ctx), key1);
c_block2[i1] = withKey(component(\`Child\`, {n: ctx['number']}, key + \`__1__\${key1}\`, node, ctx), key1);
}
let b2 = list(c2);
let b2 = list(c_block2);
return block1([], [b2]);
}
}"
@@ -269,13 +269,13 @@ exports[`list of components sub components with some state rendered in a loop 2`
return function template(ctx, node, key = \\"\\") {
ctx = Object.create(ctx);
const [k2, v2, l2, c2] = prepareList(ctx['state'].numbers);
for (let i1 = 0; i1 < l2; i1++) {
ctx[\`number\`] = v2[i1];
const [k_block2, v_block2, l_block2, c_block2] = prepareList(ctx['state'].numbers);
for (let i1 = 0; i1 < l_block2; i1++) {
ctx[\`number\`] = v_block2[i1];
let key1 = ctx['number'];
c2[i1] = withKey(component(\`Child\`, {}, key + \`__1__\${key1}\`, node, ctx), key1);
c_block2[i1] = withKey(component(\`Child\`, {}, key + \`__1__\${key1}\`, node, ctx), key1);
}
let b2 = list(c2);
let b2 = list(c_block2);
return block1([], [b2]);
}
}"
@@ -307,14 +307,14 @@ exports[`list of components t-foreach with t-component, and update 2`] = `
return function template(ctx, node, key = \\"\\") {
ctx = Object.create(ctx);
const [k2, v2, l2, c2] = prepareList(Array(2));
for (let i1 = 0; i1 < l2; i1++) {
ctx[\`n\`] = v2[i1];
const [k_block2, v_block2, l_block2, c_block2] = prepareList(Array(2));
for (let i1 = 0; i1 < l_block2; i1++) {
ctx[\`n\`] = v_block2[i1];
ctx[\`n_index\`] = i1;
let key1 = ctx['n_index'];
c2[i1] = withKey(component(\`Child\`, {val: ctx['n_index']}, key + \`__1__\${key1}\`, node, ctx), key1);
c_block2[i1] = withKey(component(\`Child\`, {val: ctx['n_index']}, key + \`__1__\${key1}\`, node, ctx), key1);
}
let b2 = list(c2);
let b2 = list(c_block2);
return block1([], [b2]);
}
}"