[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 Géry Debongnie
parent 55ef9ca116
commit 5f1e1e189f
16 changed files with 628 additions and 326 deletions
+107 -107
View File
@@ -10,13 +10,13 @@ exports[`t-foreach does not pollute the rendering context 1`] = `
return function template(ctx, node, key = \\"\\") {
ctx = Object.create(ctx);
const [k2, v2, l2, c2] = prepareList([1]);
for (let i1 = 0; i1 < l2; i1++) {
ctx[\`item\`] = v2[i1];
const [k_block2, v_block2, l_block2, c_block2] = prepareList([1]);
for (let i1 = 0; i1 < l_block2; i1++) {
ctx[\`item\`] = v_block2[i1];
let key1 = ctx['item'];
c2[i1] = withKey(text(ctx['item']), key1);
c_block2[i1] = withKey(text(ctx['item']), key1);
}
let b2 = list(c2);
let b2 = list(c_block2);
return block1([], [b2]);
}
}"
@@ -33,14 +33,14 @@ exports[`t-foreach iterate on items (on a element node) 1`] = `
return function template(ctx, node, key = \\"\\") {
ctx = Object.create(ctx);
const [k2, v2, l2, c2] = prepareList([1,2]);
for (let i1 = 0; i1 < l2; i1++) {
ctx[\`item\`] = v2[i1];
const [k_block2, v_block2, l_block2, c_block2] = prepareList([1,2]);
for (let i1 = 0; i1 < l_block2; i1++) {
ctx[\`item\`] = v_block2[i1];
let key1 = ctx['item'];
let d1 = ctx['item'];
c2[i1] = withKey(block3([d1]), key1);
c_block2[i1] = withKey(block3([d1]), key1);
}
let b2 = list(c2);
let b2 = list(c_block2);
return block1([], [b2]);
}
}"
@@ -56,11 +56,11 @@ exports[`t-foreach iterate on items 1`] = `
return function template(ctx, node, key = \\"\\") {
ctx = Object.create(ctx);
const [k2, v2, l2, c2] = prepareList([3,2,1]);
for (let i1 = 0; i1 < l2; i1++) {
ctx[\`item\`] = v2[i1];
const [k_block2, v_block2, l_block2, c_block2] = prepareList([3,2,1]);
for (let i1 = 0; i1 < l_block2; i1++) {
ctx[\`item\`] = v_block2[i1];
ctx[\`item_index\`] = i1;
ctx[\`item_value\`] = k2[i1];
ctx[\`item_value\`] = k_block2[i1];
let key1 = ctx['item'];
let b4 = text(\` [\`);
let b5 = text(ctx['item_index']);
@@ -69,9 +69,9 @@ exports[`t-foreach iterate on items 1`] = `
let b8 = text(\` \`);
let b9 = text(ctx['item_value']);
let b10 = text(\`] \`);
c2[i1] = withKey(multi([b4, b5, b6, b7, b8, b9, b10]), key1);
c_block2[i1] = withKey(multi([b4, b5, b6, b7, b8, b9, b10]), key1);
}
let b2 = list(c2);
let b2 = list(c_block2);
return block1([], [b2]);
}
}"
@@ -87,11 +87,11 @@ exports[`t-foreach iterate, dict param 1`] = `
return function template(ctx, node, key = \\"\\") {
ctx = Object.create(ctx);
const [k2, v2, l2, c2] = prepareList(ctx['value']);
for (let i1 = 0; i1 < l2; i1++) {
ctx[\`item\`] = v2[i1];
const [k_block2, v_block2, l_block2, c_block2] = prepareList(ctx['value']);
for (let i1 = 0; i1 < l_block2; i1++) {
ctx[\`item\`] = v_block2[i1];
ctx[\`item_index\`] = i1;
ctx[\`item_value\`] = k2[i1];
ctx[\`item_value\`] = k_block2[i1];
let key1 = ctx['item_index'];
let b4 = text(\` [\`);
let b5 = text(ctx['item_index']);
@@ -100,9 +100,9 @@ exports[`t-foreach iterate, dict param 1`] = `
let b8 = text(\` \`);
let b9 = text(ctx['item_value']);
let b10 = text(\`] \`);
c2[i1] = withKey(multi([b4, b5, b6, b7, b8, b9, b10]), key1);
c_block2[i1] = withKey(multi([b4, b5, b6, b7, b8, b9, b10]), key1);
}
let b2 = list(c2);
let b2 = list(c_block2);
return block1([], [b2]);
}
}"
@@ -118,11 +118,11 @@ exports[`t-foreach iterate, position 1`] = `
return function template(ctx, node, key = \\"\\") {
ctx = Object.create(ctx);
const [k2, v2, l2, c2] = prepareList(Array(5));
for (let i1 = 0; i1 < l2; i1++) {
ctx[\`elem\`] = v2[i1];
const [k_block2, v_block2, l_block2, c_block2] = prepareList(Array(5));
for (let i1 = 0; i1 < l_block2; i1++) {
ctx[\`elem\`] = v_block2[i1];
ctx[\`elem_first\`] = i1 === 0;
ctx[\`elem_last\`] = i1 === v2.length - 1;
ctx[\`elem_last\`] = i1 === v_block2.length - 1;
ctx[\`elem_index\`] = i1;
let key1 = ctx['elem'];
let b4,b5,b6,b7,b8,b9;
@@ -136,9 +136,9 @@ exports[`t-foreach iterate, position 1`] = `
b7 = text(\` (\`);
b8 = text(ctx['elem_index']);
b9 = text(\`) \`);
c2[i1] = withKey(multi([b4, b5, b6, b7, b8, b9]), key1);
c_block2[i1] = withKey(multi([b4, b5, b6, b7, b8, b9]), key1);
}
let b2 = list(c2);
let b2 = list(c_block2);
return block1([], [b2]);
}
}"
@@ -154,13 +154,13 @@ exports[`t-foreach simple iteration (in a node) 1`] = `
return function template(ctx, node, key = \\"\\") {
ctx = Object.create(ctx);
const [k2, v2, l2, c2] = prepareList([3,2,1]);
for (let i1 = 0; i1 < l2; i1++) {
ctx[\`item\`] = v2[i1];
const [k_block2, v_block2, l_block2, c_block2] = prepareList([3,2,1]);
for (let i1 = 0; i1 < l_block2; i1++) {
ctx[\`item\`] = v_block2[i1];
let key1 = ctx['item'];
c2[i1] = withKey(text(ctx['item']), key1);
c_block2[i1] = withKey(text(ctx['item']), key1);
}
let b2 = list(c2);
let b2 = list(c_block2);
return block1([], [b2]);
}
}"
@@ -174,13 +174,13 @@ exports[`t-foreach simple iteration 1`] = `
return function template(ctx, node, key = \\"\\") {
ctx = Object.create(ctx);
const [k1, v1, l1, c1] = prepareList([3,2,1]);
for (let i1 = 0; i1 < l1; i1++) {
ctx[\`item\`] = v1[i1];
const [k_block1, v_block1, l_block1, c_block1] = prepareList([3,2,1]);
for (let i1 = 0; i1 < l_block1; i1++) {
ctx[\`item\`] = v_block1[i1];
let key1 = ctx['item'];
c1[i1] = withKey(text(ctx['item']), key1);
c_block1[i1] = withKey(text(ctx['item']), key1);
}
return list(c1);
return list(c_block1);
}
}"
`;
@@ -196,17 +196,17 @@ exports[`t-foreach simple iteration with two nodes inside 1`] = `
return function template(ctx, node, key = \\"\\") {
ctx = Object.create(ctx);
const [k1, v1, l1, c1] = prepareList([3,2,1]);
for (let i1 = 0; i1 < l1; i1++) {
ctx[\`item\`] = v1[i1];
const [k_block1, v_block1, l_block1, c_block1] = prepareList([3,2,1]);
for (let i1 = 0; i1 < l_block1; i1++) {
ctx[\`item\`] = v_block1[i1];
let key1 = ctx['item'];
let d1 = ctx['item'];
let b3 = block3([d1]);
let d2 = ctx['item'];
let b4 = block4([d2]);
c1[i1] = withKey(multi([b3, b4]), key1);
c_block1[i1] = withKey(multi([b3, b4]), key1);
}
return list(c1);
return list(c_block1);
}
}"
`;
@@ -243,36 +243,36 @@ exports[`t-foreach t-call with body in t-foreach in t-foreach 2`] = `
return function template(ctx, node, key = \\"\\") {
ctx = Object.create(ctx);
ctx = Object.create(ctx);
const [k2, v2, l2, c2] = prepareList(ctx['numbers']);
for (let i1 = 0; i1 < l2; i1++) {
ctx[\`a\`] = v2[i1];
const [k_block2, v_block2, l_block2, c_block2] = prepareList(ctx['numbers']);
for (let i1 = 0; i1 < l_block2; i1++) {
ctx[\`a\`] = v_block2[i1];
ctx[\`a_first\`] = i1 === 0;
ctx[\`a_last\`] = i1 === v2.length - 1;
ctx[\`a_last\`] = i1 === v_block2.length - 1;
ctx[\`a_index\`] = i1;
ctx[\`a_value\`] = k2[i1];
ctx[\`a_value\`] = k_block2[i1];
let key1 = ctx['a'];
ctx = Object.create(ctx);
const [k4, v4, l4, c4] = prepareList(ctx['letters']);
for (let i2 = 0; i2 < l4; i2++) {
ctx[\`b\`] = v4[i2];
const [k_block4, v_block4, l_block4, c_block4] = prepareList(ctx['letters']);
for (let i2 = 0; i2 < l_block4; i2++) {
ctx[\`b\`] = v_block4[i2];
ctx[\`b_first\`] = i2 === 0;
ctx[\`b_last\`] = i2 === v4.length - 1;
ctx[\`b_last\`] = i2 === v_block4.length - 1;
ctx[\`b_index\`] = i2;
ctx[\`b_value\`] = k4[i2];
ctx[\`b_value\`] = k_block4[i2];
let key2 = ctx['b'];
ctx = Object.create(ctx);
ctx[\`c\`] = 'x'+'_'+ctx['a']+'_'+ctx['b'];
c4[i2] = withKey(callTemplate_2(ctx, node, key + \`__1__\${key1}__\${key2}\`), key2);
c_block4[i2] = withKey(callTemplate_2(ctx, node, key + \`__1__\${key1}__\${key2}\`), key2);
ctx = ctx.__proto__;
}
ctx = ctx.__proto__;
let b4 = list(c4);
let b4 = list(c_block4);
let d1 = ctx['c'];
let b6 = block6([d1]);
c2[i1] = withKey(multi([b4, b6]), key1);
c_block2[i1] = withKey(multi([b4, b6]), key1);
}
ctx = ctx.__proto__;
let b2 = list(c2);
let b2 = list(c_block2);
let d2 = ctx['a'];
let d3 = ctx['b'];
let d4 = ctx['c'];
@@ -314,33 +314,33 @@ exports[`t-foreach t-call without body in t-foreach in t-foreach 2`] = `
return function template(ctx, node, key = \\"\\") {
ctx = Object.create(ctx);
const [k2, v2, l2, c2] = prepareList(ctx['numbers']);
for (let i1 = 0; i1 < l2; i1++) {
ctx[\`a\`] = v2[i1];
const [k_block2, v_block2, l_block2, c_block2] = prepareList(ctx['numbers']);
for (let i1 = 0; i1 < l_block2; i1++) {
ctx[\`a\`] = v_block2[i1];
ctx[\`a_first\`] = i1 === 0;
ctx[\`a_last\`] = i1 === v2.length - 1;
ctx[\`a_last\`] = i1 === v_block2.length - 1;
ctx[\`a_index\`] = i1;
ctx[\`a_value\`] = k2[i1];
ctx[\`a_value\`] = k_block2[i1];
let key1 = ctx['a'];
ctx = Object.create(ctx);
const [k4, v4, l4, c4] = prepareList(ctx['letters']);
for (let i2 = 0; i2 < l4; i2++) {
ctx[\`b\`] = v4[i2];
const [k_block4, v_block4, l_block4, c_block4] = prepareList(ctx['letters']);
for (let i2 = 0; i2 < l_block4; i2++) {
ctx[\`b\`] = v_block4[i2];
ctx[\`b_first\`] = i2 === 0;
ctx[\`b_last\`] = i2 === v4.length - 1;
ctx[\`b_last\`] = i2 === v_block4.length - 1;
ctx[\`b_index\`] = i2;
ctx[\`b_value\`] = k4[i2];
ctx[\`b_value\`] = k_block4[i2];
let key2 = ctx['b'];
c4[i2] = withKey(callTemplate_2(ctx, node, key + \`__1__\${key1}__\${key2}\`), key2);
c_block4[i2] = withKey(callTemplate_2(ctx, node, key + \`__1__\${key1}__\${key2}\`), key2);
}
ctx = ctx.__proto__;
let b4 = list(c4);
let b4 = list(c_block4);
let d1 = ctx['c'];
let b6 = block6([d1]);
c2[i1] = withKey(multi([b4, b6]), key1);
c_block2[i1] = withKey(multi([b4, b6]), key1);
}
ctx = ctx.__proto__;
let b2 = list(c2);
let b2 = list(c_block2);
let d2 = ctx['a'];
let d3 = ctx['b'];
let d4 = ctx['c'];
@@ -359,25 +359,25 @@ exports[`t-foreach t-foreach in t-foreach 1`] = `
return function template(ctx, node, key = \\"\\") {
ctx = Object.create(ctx);
const [k2, v2, l2, c2] = prepareList(ctx['numbers']);
for (let i1 = 0; i1 < l2; i1++) {
ctx[\`number\`] = v2[i1];
const [k_block2, v_block2, l_block2, c_block2] = prepareList(ctx['numbers']);
for (let i1 = 0; i1 < l_block2; i1++) {
ctx[\`number\`] = v_block2[i1];
let key1 = ctx['number'];
ctx = Object.create(ctx);
const [k3, v3, l3, c3] = prepareList(ctx['letters']);
for (let i2 = 0; i2 < l3; i2++) {
ctx[\`letter\`] = v3[i2];
const [k_block3, v_block3, l_block3, c_block3] = prepareList(ctx['letters']);
for (let i2 = 0; i2 < l_block3; i2++) {
ctx[\`letter\`] = v_block3[i2];
let key2 = ctx['letter'];
let b5 = text(\` [\`);
let b6 = text(ctx['number']);
let b7 = text(ctx['letter']);
let b8 = text(\`] \`);
c3[i2] = withKey(multi([b5, b6, b7, b8]), key2);
c_block3[i2] = withKey(multi([b5, b6, b7, b8]), 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]);
}
}"
@@ -393,18 +393,18 @@ exports[`t-foreach t-foreach with t-if inside (no external node) 1`] = `
return function template(ctx, node, key = \\"\\") {
ctx = Object.create(ctx);
const [k1, v1, l1, c1] = prepareList(ctx['elems']);
for (let i1 = 0; i1 < l1; i1++) {
ctx[\`elem\`] = v1[i1];
const [k_block1, v_block1, l_block1, c_block1] = prepareList(ctx['elems']);
for (let i1 = 0; i1 < l_block1; i1++) {
ctx[\`elem\`] = v_block1[i1];
let key1 = ctx['elem'].id;
let b3;
if (ctx['elem'].id<3) {
let d1 = ctx['elem'].text;
b3 = block3([d1]);
}
c1[i1] = withKey(multi([b3]), key1);
c_block1[i1] = withKey(multi([b3]), key1);
}
return list(c1);
return list(c_block1);
}
}"
`;
@@ -420,18 +420,18 @@ exports[`t-foreach t-foreach with t-if inside 1`] = `
return function template(ctx, node, key = \\"\\") {
ctx = Object.create(ctx);
const [k2, v2, l2, c2] = prepareList(ctx['elems']);
for (let i1 = 0; i1 < l2; i1++) {
ctx[\`elem\`] = v2[i1];
const [k_block2, v_block2, l_block2, c_block2] = prepareList(ctx['elems']);
for (let i1 = 0; i1 < l_block2; i1++) {
ctx[\`elem\`] = v_block2[i1];
let key1 = ctx['elem'].id;
let b4;
if (ctx['elem'].id<3) {
let d1 = ctx['elem'].text;
b4 = block4([d1]);
}
c2[i1] = withKey(multi([b4]), key1);
c_block2[i1] = withKey(multi([b4]), key1);
}
let b2 = list(c2);
let b2 = list(c_block2);
return block1([], [b2]);
}
}"
@@ -448,14 +448,14 @@ exports[`t-foreach throws error if invalid loop expression 1`] = `
return function template(ctx, node, key = \\"\\") {
ctx = Object.create(ctx);
const [k2, v2, l2, c2] = prepareList(ctx['abc']);
for (let i1 = 0; i1 < l2; i1++) {
ctx[\`item\`] = v2[i1];
const [k_block2, v_block2, l_block2, c_block2] = prepareList(ctx['abc']);
for (let i1 = 0; i1 < l_block2; i1++) {
ctx[\`item\`] = v_block2[i1];
ctx[\`item_index\`] = i1;
let key1 = ctx['item'];
c2[i1] = withKey(block3(), key1);
c_block2[i1] = withKey(block3(), key1);
}
let b2 = list(c2);
let b2 = list(c_block2);
return block1([], [b2]);
}
}"
@@ -472,14 +472,14 @@ exports[`t-foreach warn if no key in some case 1`] = `
return function template(ctx, node, key = \\"\\") {
ctx = Object.create(ctx);
const [k2, v2, l2, c2] = prepareList([1,2]);
for (let i1 = 0; i1 < l2; i1++) {
ctx[\`item\`] = v2[i1];
const [k_block2, v_block2, l_block2, c_block2] = prepareList([1,2]);
for (let i1 = 0; i1 < l_block2; i1++) {
ctx[\`item\`] = v_block2[i1];
let key1 = i1;
let d1 = ctx['item'];
c2[i1] = withKey(block3([d1]), key1);
c_block2[i1] = withKey(block3([d1]), key1);
}
let b2 = list(c2);
let b2 = list(c_block2);
return block1([], [b2]);
}
}"
@@ -499,25 +499,25 @@ exports[`t-foreach with t-memo 1`] = `
let cache = ctx.cache || {};
let nextCache = ctx.cache = {};
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 = ctx['item'].id;
let memo1 = [ctx['item'].x]
let vnode1 = cache[key1];
if (vnode1) {
if (shallowEqual(vnode1.memo, memo1)) {
c2[i1] = vnode1;
c_block2[i1] = vnode1;
nextCache[key1] = vnode1;
continue;
}
}
let d1 = ctx['item'].x;
let d2 = ctx['item'].y;
c2[i1] = withKey(block3([d1, d2]), key1);
nextCache[key1] = assign(c2[i1], {memo: memo1});
c_block2[i1] = withKey(block3([d1, d2]), key1);
nextCache[key1] = assign(c_block2[i1], {memo: memo1});
}
let b2 = list(c2);
let b2 = list(c_block2);
return block1([], [b2]);
}
}"