diff --git a/src/qweb/compiler.ts b/src/qweb/compiler.ts index 7ab544f1..8860b653 100644 --- a/src/qweb/compiler.ts +++ b/src/qweb/compiler.ts @@ -96,7 +96,7 @@ class BlockDescription { } return `${this.blockName}(${params})`; } else if (this.type === "list") { - return `list(c${this.id})`; + return `list(c_block${this.id})`; } return expr; } @@ -246,7 +246,7 @@ export class QWebCompiler { if (parentBlock) { parentBlock.children.push(block); if (parentBlock.type === "list") { - block.parentVar = `c${parentBlock.id}`; + block.parentVar = `c_block${parentBlock.id}`; } } return block; @@ -693,11 +693,10 @@ export class QWebCompiler { this.target.loopLevel++; const loopVar = `i${this.target.loopLevel}`; this.addLine(`ctx = Object.create(ctx);`); - // const cId = this.generateId(); - const vals = `v${block.id}`; - const keys = `k${block.id}`; - const l = `l${block.id}`; - const c = `c${block.id}`; + const vals = `v_block${block.id}`; + const keys = `k_block${block.id}`; + const l = `l_block${block.id}`; + const c = `c_block${block.id}`; this.addLine( `const [${keys}, ${vals}, ${l}, ${c}] = prepareList(${compileExpr(ast.collection)});` ); diff --git a/tests/components/__snapshots__/basics.test.ts.snap b/tests/components/__snapshots__/basics.test.ts.snap index 82c79418..327a35e6 100644 --- a/tests/components/__snapshots__/basics.test.ts.snap +++ b/tests/components/__snapshots__/basics.test.ts.snap @@ -463,15 +463,15 @@ exports[`basics list of two 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(\`SubWidget\`, {}, key + \`__1__\${key1}\`, node, ctx); let b5 = component(\`SubWidget\`, {}, key + \`__2__\${key1}\`, node, ctx); - c2[i1] = withKey(block3([], [b4, b5]), key1); + c_block2[i1] = withKey(block3([], [b4, b5]), key1); } - let b2 = list(c2); + let b2 = list(c_block2); return block1([], [b2]); } }" @@ -995,13 +995,13 @@ exports[`basics updating a component with t-foreach as root 1`] = ` return function template(ctx, node, key = \\"\\") { ctx = Object.create(ctx); - const [k1, v1, l1, c1] = prepareList(ctx['items']); - for (let i1 = 0; i1 < l1; i1++) { - ctx[\`item\`] = v1[i1]; + const [k_block1, v_block1, l_block1, c_block1] = prepareList(ctx['items']); + 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); } }" `; @@ -1030,15 +1030,15 @@ exports[`basics widget after a t-foreach 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[\`elem\`] = v2[i1]; + const [k_block2, v_block2, l_block2, c_block2] = prepareList(Array(2)); + for (let i1 = 0; i1 < l_block2; i1++) { + ctx[\`elem\`] = v_block2[i1]; ctx[\`elem_index\`] = i1; let key1 = ctx['elem_index']; - c2[i1] = withKey(text(\`txt\`), key1); + c_block2[i1] = withKey(text(\`txt\`), key1); } ctx = ctx.__proto__; - let b2 = list(c2); + let b2 = list(c_block2); let b4 = component(\`SomeComponent\`, {}, key + \`__1\`, node, ctx); return block1([], [b2, b4]); } diff --git a/tests/components/__snapshots__/slots.test.ts.snap b/tests/components/__snapshots__/slots.test.ts.snap index 0f3feb3d..6992085b 100644 --- a/tests/components/__snapshots__/slots.test.ts.snap +++ b/tests/components/__snapshots__/slots.test.ts.snap @@ -1502,15 +1502,15 @@ exports[`slots slots are rendered with proper context, part 2 2`] = ` return function template(ctx, node, key = \\"\\") { ctx = Object.create(ctx); - const [k2, v2, l2, c2] = prepareList(ctx['state'].users); - for (let i1 = 0; i1 < l2; i1++) { - ctx[\`user\`] = v2[i1]; + const [k_block2, v_block2, l_block2, c_block2] = prepareList(ctx['state'].users); + for (let i1 = 0; i1 < l_block2; i1++) { + ctx[\`user\`] = v_block2[i1]; let key1 = ctx['user'].id; const ctx2 = capture(ctx); let b7 = assign(component(\`Link\`, {to: '/user/'+ctx['user'].id}, key + \`__1__\${key1}\`, node, ctx), {slots: {'default': slot3(ctx2)}}); - c2[i1] = withKey(block3([], [b7]), key1); + c_block2[i1] = withKey(block3([], [b7]), key1); } - let b2 = list(c2); + let b2 = list(c_block2); return block1([], [b2]); } }" @@ -1549,16 +1549,16 @@ exports[`slots slots are rendered with proper context, part 3 2`] = ` return function template(ctx, node, key = \\"\\") { ctx = Object.create(ctx); ctx = Object.create(ctx); - const [k2, v2, l2, c2] = prepareList(ctx['state'].users); - for (let i1 = 0; i1 < l2; i1++) { - ctx[\`user\`] = v2[i1]; + const [k_block2, v_block2, l_block2, c_block2] = prepareList(ctx['state'].users); + for (let i1 = 0; i1 < l_block2; i1++) { + ctx[\`user\`] = v_block2[i1]; let key1 = ctx['user'].id; ctx[\`userdescr\`] = 'User '+ctx['user'].name; const ctx2 = capture(ctx); let b5 = assign(component(\`Link\`, {to: '/user/'+ctx['user'].id}, key + \`__1__\${key1}\`, node, ctx), {slots: {'default': slot3(ctx2)}}); - c2[i1] = withKey(block3([], [b5]), key1); + c_block2[i1] = withKey(block3([], [b5]), key1); } - let b2 = list(c2); + let b2 = list(c_block2); return block1([], [b2]); } }" @@ -1694,15 +1694,15 @@ exports[`slots slots in t-foreach and re-rendering 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']; const ctx2 = capture(ctx); - c2[i1] = withKey(assign(component(\`Child\`, {}, key + \`__1__\${key1}\`, node, ctx), {slots: {'default': slot3(ctx2)}}), key1); + c_block2[i1] = withKey(assign(component(\`Child\`, {}, key + \`__1__\${key1}\`, node, ctx), {slots: {'default': slot3(ctx2)}}), key1); } - let b2 = list(c2); + let b2 = list(c_block2); return block1([], [b2]); } }" @@ -1742,26 +1742,26 @@ exports[`slots slots in t-foreach in t-foreach 2`] = ` return function template(ctx, node, key = \\"\\") { ctx = Object.create(ctx); - const [k2, v2, l2, c2] = prepareList(ctx['tree']); - for (let i1 = 0; i1 < l2; i1++) { - ctx[\`node1\`] = v2[i1]; + const [k_block2, v_block2, l_block2, c_block2] = prepareList(ctx['tree']); + for (let i1 = 0; i1 < l_block2; i1++) { + ctx[\`node1\`] = v_block2[i1]; let key1 = ctx['node1'].key; let d1 = ctx['node1'].value; let b4 = block4([d1]); ctx = Object.create(ctx); - const [k6, v6, l6, c6] = prepareList(ctx['node1'].nodes); - for (let i2 = 0; i2 < l6; i2++) { - ctx[\`node2\`] = v6[i2]; + const [k_block6, v_block6, l_block6, c_block6] = prepareList(ctx['node1'].nodes); + for (let i2 = 0; i2 < l_block6; i2++) { + ctx[\`node2\`] = v_block6[i2]; let key2 = ctx['node2'].key; const ctx2 = capture(ctx); - c6[i2] = withKey(assign(component(\`Child\`, {}, key + \`__1__\${key1}__\${key2}\`, node, ctx), {slots: {'default': slot3(ctx2)}}), key2); + c_block6[i2] = withKey(assign(component(\`Child\`, {}, key + \`__1__\${key1}__\${key2}\`, node, ctx), {slots: {'default': slot3(ctx2)}}), key2); } ctx = ctx.__proto__; - let b6 = list(c6); + let b6 = list(c_block6); let b5 = block5([], [b6]); - c2[i1] = withKey(multi([b4, b5]), key1); + c_block2[i1] = withKey(multi([b4, b5]), key1); } - let b2 = list(c2); + let b2 = list(c_block2); return block1([], [b2]); } }" @@ -1799,16 +1799,16 @@ exports[`slots slots in t-foreach with t-set and re-rendering 2`] = ` return function template(ctx, node, key = \\"\\") { ctx = Object.create(ctx); 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']; ctx[\`dummy\`] = ctx['n_index']; const ctx2 = capture(ctx); - c2[i1] = withKey(assign(component(\`Child\`, {}, key + \`__1__\${key1}\`, node, ctx), {slots: {'default': slot3(ctx2)}}), key1); + c_block2[i1] = withKey(assign(component(\`Child\`, {}, key + \`__1__\${key1}\`, node, ctx), {slots: {'default': slot3(ctx2)}}), key1); } - let b2 = list(c2); + let b2 = list(c_block2); return block1([], [b2]); } }" @@ -1915,13 +1915,13 @@ exports[`slots t-slot in recursive templates 2`] = ` const slot3 = ctx => (node, key) => { let b2 = text(ctx['name']); ctx = Object.create(ctx); - const [k3, v3, l3, c3] = prepareList(ctx['items']); - for (let i1 = 0; i1 < l3; i1++) { - ctx[\`item\`] = v3[i1]; + const [k_block3, v_block3, l_block3, c_block3] = prepareList(ctx['items']); + for (let i1 = 0; i1 < l_block3; i1++) { + ctx[\`item\`] = v_block3[i1]; ctx[\`item_first\`] = i1 === 0; - ctx[\`item_last\`] = i1 === v3.length - 1; + ctx[\`item_last\`] = i1 === v_block3.length - 1; ctx[\`item_index\`] = i1; - ctx[\`item_value\`] = k3[i1]; + ctx[\`item_value\`] = k_block3[i1]; let key1 = ctx['item'].name; let b5,b6; if (!ctx['item'].children.length) { @@ -1933,10 +1933,10 @@ exports[`slots t-slot in recursive templates 2`] = ` b6 = callTemplate_5(ctx, node, key + \`__4__\${key1}\`); ctx = ctx.__proto__; } - c3[i1] = withKey(multi([b5, b6]), key1); + c_block3[i1] = withKey(multi([b5, b6]), key1); } ctx = ctx.__proto__; - let b3 = list(c3); + let b3 = list(c_block3); return multi([b2, b3]); } diff --git a/tests/components/__snapshots__/t_call.test.ts.snap b/tests/components/__snapshots__/t_call.test.ts.snap index a1ed3fb7..9c256d31 100644 --- a/tests/components/__snapshots__/t_call.test.ts.snap +++ b/tests/components/__snapshots__/t_call.test.ts.snap @@ -275,17 +275,17 @@ exports[`t-call t-call in t-foreach and children component 3`] = ` return function template(ctx, node, key = \\"\\") { ctx = Object.create(ctx); - const [k2, v2, l2, c2] = prepareList(['a','b','c']); - for (let i1 = 0; i1 < l2; i1++) { - ctx[\`val\`] = v2[i1]; + const [k_block2, v_block2, l_block2, c_block2] = prepareList(['a','b','c']); + for (let i1 = 0; i1 < l_block2; i1++) { + ctx[\`val\`] = v_block2[i1]; ctx[\`val_first\`] = i1 === 0; - ctx[\`val_last\`] = i1 === v2.length - 1; + ctx[\`val_last\`] = i1 === v_block2.length - 1; ctx[\`val_index\`] = i1; - ctx[\`val_value\`] = k2[i1]; + ctx[\`val_value\`] = k_block2[i1]; let key1 = ctx['val']; - c2[i1] = withKey(callTemplate_2(ctx, node, key + \`__1__\${key1}\`), key1); + c_block2[i1] = withKey(callTemplate_2(ctx, node, key + \`__1__\${key1}\`), key1); } - let b2 = list(c2); + let b2 = list(c_block2); return block1([], [b2]); } }" diff --git a/tests/components/__snapshots__/t_foreach.test.ts.snap b/tests/components/__snapshots__/t_foreach.test.ts.snap index 53856f75..af6c42cb 100644 --- a/tests/components/__snapshots__/t_foreach.test.ts.snap +++ b/tests/components/__snapshots__/t_foreach.test.ts.snap @@ -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]); } }" diff --git a/tests/components/__snapshots__/t_on.test.ts.snap b/tests/components/__snapshots__/t_on.test.ts.snap new file mode 100644 index 00000000..1b50a452 --- /dev/null +++ b/tests/components/__snapshots__/t_on.test.ts.snap @@ -0,0 +1,153 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`t-on t-on expression captured in t-foreach 1`] = ` +"function anonymous(bdom, helpers +) { + let { text, createBlock, list, multi, html, toggler, component } = bdom; + let { withDefault, getTemplate, prepareList, withKey, zero, call, callSlot, capture, shallowEqual } = helpers; + + let block1 = createBlock(\`
\`); + let block3 = createBlock(\`
\`); + + return function template(ctx, node, key = \\"\\") { + ctx = Object.create(ctx); + ctx[\`iter\`] = 0; + ctx = Object.create(ctx); + const [k_block2, v_block2, l_block2, c_block2] = prepareList(ctx['arr']); + for (let i1 = 0; i1 < l_block2; i1++) { + ctx[\`val\`] = v_block2[i1]; + let key1 = ctx['val']; + const v1 = ctx['otherState']; + const v2 = ctx['iter']; + let d1 = (e) => {const res = (() => { return v1.vals.push(v2+'_'+v2) })(); if (typeof res === 'function') { res(e) }}; + ctx[\`iter\`] = ctx['iter']+1; + c_block2[i1] = withKey(block3([d1]), key1); + } + let b2 = list(c_block2); + return block1([], [b2]); + } +}" +`; + +exports[`t-on t-on expression in t-foreach 1`] = ` +"function anonymous(bdom, helpers +) { + let { text, createBlock, list, multi, html, toggler, component } = bdom; + let { withDefault, getTemplate, prepareList, withKey, zero, call, callSlot, capture, shallowEqual } = helpers; + + let block1 = createBlock(\`
\`); + let block3 = createBlock(\`
:
\`); + + return function template(ctx, node, key = \\"\\") { + ctx = Object.create(ctx); + const [k_block2, v_block2, l_block2, c_block2] = prepareList(ctx['state'].values); + for (let i1 = 0; i1 < l_block2; i1++) { + ctx[\`val\`] = v_block2[i1]; + ctx[\`val_index\`] = i1; + let key1 = ctx['val']; + let d1 = ctx['val_index']; + let d2 = ctx['val']+''; + const v1 = ctx['otherState']; + const v2 = ctx['val']; + let d3 = (e) => {const res = (() => { return v1.vals.push(v2) })(); if (typeof res === 'function') { res(e) }}; + c_block2[i1] = withKey(block3([d1, d2, d3]), key1); + } + let b2 = list(c_block2); + return block1([], [b2]); + } +}" +`; + +exports[`t-on t-on expression in t-foreach with t-set 1`] = ` +"function anonymous(bdom, helpers +) { + let { text, createBlock, list, multi, html, toggler, component } = bdom; + let { withDefault, getTemplate, prepareList, withKey, zero, call, callSlot, capture, shallowEqual } = helpers; + + let block1 = createBlock(\`
\`); + let block3 = createBlock(\`
:
\`); + + return function template(ctx, node, key = \\"\\") { + ctx = Object.create(ctx); + ctx[\`bossa\`] = 'nova'; + ctx = Object.create(ctx); + const [k_block2, v_block2, l_block2, c_block2] = prepareList(ctx['state'].values); + for (let i1 = 0; i1 < l_block2; i1++) { + ctx[\`val\`] = v_block2[i1]; + ctx[\`val_index\`] = i1; + let key1 = ctx['val']; + ctx[\`bossa\`] = ctx['bossa']+'_'+ctx['val_index']; + let d1 = ctx['val_index']; + let d2 = ctx['val']+''; + const v1 = ctx['otherState']; + const v2 = ctx['val']; + const v3 = ctx['bossa']; + let d3 = (e) => {const res = (() => { return v1.vals.push(v2+'_'+v3) })(); if (typeof res === 'function') { res(e) }}; + c_block2[i1] = withKey(block3([d1, d2, d3]), key1); + } + let b2 = list(c_block2); + return block1([], [b2]); + } +}" +`; + +exports[`t-on t-on method call in t-foreach 1`] = ` +"function anonymous(bdom, helpers +) { + let { text, createBlock, list, multi, html, toggler, component } = bdom; + let { withDefault, getTemplate, prepareList, withKey, zero, call, callSlot, capture, shallowEqual } = helpers; + + let block1 = createBlock(\`
\`); + let block3 = createBlock(\`
:
\`); + + return function template(ctx, node, key = \\"\\") { + ctx = Object.create(ctx); + const [k_block2, v_block2, l_block2, c_block2] = prepareList(ctx['state'].values); + for (let i1 = 0; i1 < l_block2; i1++) { + ctx[\`val\`] = v_block2[i1]; + ctx[\`val_index\`] = i1; + let key1 = ctx['val']; + let d1 = ctx['val_index']; + let d2 = ctx['val']+''; + const arg1 = [ctx['val']]; + let d3 = [ctx, 'addVal', arg1]; + c_block2[i1] = withKey(block3([d1, d2, d3]), key1); + } + let b2 = list(c_block2); + return block1([], [b2]); + } +}" +`; + +exports[`t-on t-on on destroyed components 1`] = ` +"function anonymous(bdom, helpers +) { + let { text, createBlock, list, multi, html, toggler, component } = bdom; + let { withDefault, getTemplate, prepareList, withKey, zero, call, callSlot, capture, shallowEqual } = helpers; + + let block1 = createBlock(\`
\`); + + return function template(ctx, node, key = \\"\\") { + let d1 = [ctx, 'onClick']; + return block1([d1]); + } +}" +`; + +exports[`t-on t-on on destroyed components 2`] = ` +"function anonymous(bdom, helpers +) { + let { text, createBlock, list, multi, html, toggler, component } = bdom; + let { withDefault, getTemplate, prepareList, withKey, zero, call, callSlot, capture, shallowEqual } = helpers; + + let block1 = createBlock(\`
\`); + + return function template(ctx, node, key = \\"\\") { + let b2; + if (ctx['state'].flag) { + b2 = component(\`Child\`, {}, key + \`__1\`, node, ctx); + } + return block1([], [b2]); + } +}" +`; diff --git a/tests/components/basics.test.ts b/tests/components/basics.test.ts index 4a86ad4e..cafe0584 100644 --- a/tests/components/basics.test.ts +++ b/tests/components/basics.test.ts @@ -718,7 +718,9 @@ describe("basics", () => { await nextTick(); expect(Object.values(parent.__owl__.children)[0].component).toBe(child); expect(status(child)).toBe("mounted"); - expect(fixture.innerHTML).toBe(`

hey

childtest
`) + expect(fixture.innerHTML).toBe( + `

hey

childtest
` + ); }); test("list of two sub components inside other nodes", async () => { diff --git a/tests/components/lifecycle.test.ts b/tests/components/lifecycle.test.ts index 796a82ca..6f8942e4 100644 --- a/tests/components/lifecycle.test.ts +++ b/tests/components/lifecycle.test.ts @@ -919,7 +919,9 @@ describe("lifecycle hooks", () => { static template = xml`
`; setup() { created = true; - onMounted(() => { mounted = true; }) + onMounted(() => { + mounted = true; + }); } } class Parent extends Component { diff --git a/tests/components/style_class.test.ts b/tests/components/style_class.test.ts index 529c4f49..2f75798f 100644 --- a/tests/components/style_class.test.ts +++ b/tests/components/style_class.test.ts @@ -244,7 +244,7 @@ describe("style and class handling", () => { state = useState({ d: true }); } class Parent extends Component { - static template = xml`` + static template = xml``; static components = { Child }; state = useState({ b: true }); child = useRef("child"); @@ -319,7 +319,7 @@ describe("style and class handling", () => { expect(fixture.innerHTML).toBe(`
`); - widget.state.style["font-size"] = "30px" ; + widget.state.style["font-size"] = "30px"; await nextTick(); expect(fixture.innerHTML).toBe(`
`); @@ -341,7 +341,8 @@ describe("style and class handling", () => { error = e; } expect(error).toBeDefined(); - const regexp = /Cannot read properties of undefined \(reading 'crash'\)|Cannot read property 'crash' of undefined/g; + const regexp = + /Cannot read properties of undefined \(reading 'crash'\)|Cannot read property 'crash' of undefined/g; expect(error.message).toMatch(regexp); expect(fixture.innerHTML).toBe(""); }); diff --git a/tests/components/t_on.test.ts b/tests/components/t_on.test.ts new file mode 100644 index 00000000..f380cd9a --- /dev/null +++ b/tests/components/t_on.test.ts @@ -0,0 +1,145 @@ +import { Component, mount, onMounted, useState, xml } from "../../src/index"; +import { makeTestFixture, nextTick, snapshotEverything } from "../helpers"; +import { status } from "../../src/component/status"; + +snapshotEverything(); + +let fixture: HTMLElement; + +beforeEach(() => { + fixture = makeTestFixture(); +}); + +describe("t-on", () => { + test("t-on on destroyed components", async () => { + const steps: string[] = []; + let child; + class Child extends Component { + static template = xml`
`; + setup() { + onMounted(() => { + child = this; + }); + } + onClick() { + steps.push("click"); + } + } + class Parent extends Component { + static template = xml`
`; + static components = { Child }; + state = useState({ flag: true }); + } + const parent = await mount(Parent, fixture); + let el = (child as any).el as HTMLElement; + el.click(); + expect(steps).toEqual(["click"]); + (parent as any).state.flag = false; + await nextTick(); + expect(status(child as any)).toBe("destroyed"); + el.click(); + expect(steps).toEqual(["click"]); + }); + + test("t-on expression in t-foreach", async () => { + class Comp extends Component { + static template = xml` +
+
+ : + +
+
+ `; + state = useState({ values: ["a", "b"] }); + otherState = { vals: [] }; + } + const comp = await mount(Comp, fixture); + expect(fixture.innerHTML).toBe( + "
0: a
1: b
" + ); + expect(comp.otherState.vals).toStrictEqual([]); + const buttons = fixture.querySelectorAll("button"); + buttons[0].click(); + buttons[1].click(); + expect(comp.otherState.vals).toStrictEqual(["a", "b"]); + }); + + test("t-on expression in t-foreach with t-set", async () => { + class Comp extends Component { + static template = xml` +
+ +
+ + : + +
+
+ `; + state = useState({ values: ["a", "b"] }); + otherState = { vals: [] }; + } + const comp = await mount(Comp, fixture); + expect(fixture.innerHTML).toBe( + "
0: a
1: b
" + ); + expect(comp.otherState.vals).toStrictEqual([]); + const buttons = fixture.querySelectorAll("button"); + buttons[0].click(); + buttons[1].click(); + expect(comp.otherState.vals).toStrictEqual(["a_nova_0", "b_nova_0_1"]); + }); + + test("t-on method call in t-foreach", async () => { + class Comp extends Component { + static template = xml` +
+
+ : + +
+
+ `; + state = useState({ values: ["a", "b"] }); + otherState = { vals: new Array() }; + addVal(val: string) { + this.otherState.vals.push(val); + } + } + const comp = await mount(Comp, fixture); + expect(fixture.innerHTML).toBe( + "
0: a
1: b
" + ); + expect(comp.otherState.vals).toStrictEqual([]); + const buttons = fixture.querySelectorAll("button"); + buttons[0].click(); + buttons[1].click(); + expect(comp.otherState.vals).toStrictEqual(["a", "b"]); + }); + + test("t-on expression captured in t-foreach", async () => { + class Comp extends Component { + static template = xml` +
+ +
+ + +
+
+ `; + arr = ["a", "b"]; + otherState = { vals: new Array() }; + } + const comp = await mount(Comp, fixture); + expect(fixture.innerHTML).toBe( + "
" + ); + expect(comp.otherState.vals).toStrictEqual([]); + const buttons = fixture.querySelectorAll("button"); + buttons[0].click(); + buttons[1].click(); + expect(comp.otherState.vals).toStrictEqual(["0_0", "1_1"]); + }); +}); diff --git a/tests/qweb/__snapshots__/event_handling.test.ts.snap b/tests/qweb/__snapshots__/event_handling.test.ts.snap index 97f01bd7..23ff0ff1 100644 --- a/tests/qweb/__snapshots__/event_handling.test.ts.snap +++ b/tests/qweb/__snapshots__/event_handling.test.ts.snap @@ -74,16 +74,16 @@ exports[`t-on can bind handlers with empty object (with non empty inner string) return function template(ctx, node, key = \\"\\") { ctx = Object.create(ctx); - const [k2, v2, l2, c2] = prepareList(['someval']); - for (let i1 = 0; i1 < l2; i1++) { - ctx[\`action\`] = v2[i1]; + const [k_block2, v_block2, l_block2, c_block2] = prepareList(['someval']); + for (let i1 = 0; i1 < l_block2; i1++) { + ctx[\`action\`] = v_block2[i1]; ctx[\`action_index\`] = i1; let key1 = ctx['action_index']; const arg1 = [ctx['action']]; let d1 = [ctx, 'activate', arg1]; - 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]); } }" @@ -146,14 +146,14 @@ exports[`t-on handler is bound to proper owner, part 2 1`] = ` return function template(ctx, node, key = \\"\\") { ctx = Object.create(ctx); - const [k1, v1, l1, c1] = prepareList([1]); - for (let i1 = 0; i1 < l1; i1++) { - ctx[\`value\`] = v1[i1]; + const [k_block1, v_block1, l_block1, c_block1] = prepareList([1]); + for (let i1 = 0; i1 < l_block1; i1++) { + ctx[\`value\`] = v_block1[i1]; let key1 = ctx['value']; let d1 = [ctx, 'add']; - c1[i1] = withKey(block2([d1]), key1); + c_block1[i1] = withKey(block2([d1]), key1); } - return list(c1); + return list(c_block1); } }" `; @@ -210,17 +210,17 @@ exports[`t-on handler is bound to proper owner, part 4 2`] = ` return function template(ctx, node, key = \\"\\") { ctx = Object.create(ctx); - const [k1, v1, l1, c1] = prepareList([1]); - for (let i1 = 0; i1 < l1; i1++) { - ctx[\`value\`] = v1[i1]; + const [k_block1, v_block1, l_block1, c_block1] = prepareList([1]); + for (let i1 = 0; i1 < l_block1; i1++) { + ctx[\`value\`] = v_block1[i1]; ctx[\`value_first\`] = i1 === 0; - ctx[\`value_last\`] = i1 === v1.length - 1; + ctx[\`value_last\`] = i1 === v_block1.length - 1; ctx[\`value_index\`] = i1; - ctx[\`value_value\`] = k1[i1]; + ctx[\`value_value\`] = k_block1[i1]; let key1 = ctx['value']; - c1[i1] = withKey(callTemplate_2(ctx, node, key + \`__1__\${key1}\`), key1); + c_block1[i1] = withKey(callTemplate_2(ctx, node, key + \`__1__\${key1}\`), key1); } - return list(c1); + return list(c_block1); } }" `; diff --git a/tests/qweb/__snapshots__/misc.test.ts.snap b/tests/qweb/__snapshots__/misc.test.ts.snap index f9c3efae..a011278c 100644 --- a/tests/qweb/__snapshots__/misc.test.ts.snap +++ b/tests/qweb/__snapshots__/misc.test.ts.snap @@ -30,27 +30,27 @@ exports[`misc complex template 1`] = ` b3 = block3(); } ctx = Object.create(ctx); - const [k4, v4, l4, c4] = prepareList(ctx['batch'].slot_ids.filter(slot=>slot.build_id.id&&!slot.trigger_id.manual&&(ctx['options'].trigger_display[slot.trigger_id.id]))); - for (let i1 = 0; i1 < l4; i1++) { - ctx[\`slot\`] = v4[i1]; + const [k_block4, v_block4, l_block4, c_block4] = prepareList(ctx['batch'].slot_ids.filter(slot=>slot.build_id.id&&!slot.trigger_id.manual&&(ctx['options'].trigger_display[slot.trigger_id.id]))); + for (let i1 = 0; i1 < l_block4; i1++) { + ctx[\`slot\`] = v_block4[i1]; let key1 = ctx['slot'].id; - c4[i1] = withKey(component(\`SlotButton\`, {class: ctx['slot_container'],slot: ctx['slot']}, key + \`__1__\${key1}\`, node, ctx), key1); + c_block4[i1] = withKey(component(\`SlotButton\`, {class: ctx['slot_container'],slot: ctx['slot']}, key + \`__1__\${key1}\`, node, ctx), key1); } ctx = ctx.__proto__; - b4 = list(c4); + b4 = list(c_block4); ctx = Object.create(ctx); - const [k6, v6, l6, c6] = prepareList([1,2,3,4]); - for (let i1 = 0; i1 < l6; i1++) { - ctx[\`x\`] = v6[i1]; + const [k_block6, v_block6, l_block6, c_block6] = prepareList([1,2,3,4]); + for (let i1 = 0; i1 < l_block6; i1++) { + ctx[\`x\`] = v_block6[i1]; let key1 = ctx['x']; - c6[i1] = withKey(block7(), key1); + c_block6[i1] = withKey(block7(), key1); } ctx = ctx.__proto__; - b6 = list(c6); + b6 = list(c_block6); ctx = Object.create(ctx); - const [k8, v8, l8, c8] = prepareList(ctx['commit_links']); - for (let i1 = 0; i1 < l8; i1++) { - ctx[\`commit_link\`] = v8[i1]; + const [k_block8, v_block8, l_block8, c_block8] = prepareList(ctx['commit_links']); + for (let i1 = 0; i1 < l_block8; i1++) { + ctx[\`commit_link\`] = v_block8[i1]; let key1 = ctx['commit_link'].id; let b10,b11,b12,b13; let d6 = \`/runbot/commit/\${ctx['commit_link'].commit_id}\`; @@ -70,9 +70,9 @@ exports[`misc complex template 1`] = ` let d8 = ctx['commit_link'].commit_dname; let d9 = 'https://%s/commit/%s'%(ctx['commit_link'].commit_remote_url,ctx['commit_link'].commit_name); let d10 = ctx['commit_link'].commit_subject; - c8[i1] = withKey(block9([d6, d7, d8, d9, d10], [b10, b11, b12, b13]), key1); + c_block8[i1] = withKey(block9([d6, d7, d8, d9, d10], [b10, b11, b12, b13]), key1); } - b8 = list(c8); + b8 = list(c_block8); return block1([d1, d2, d3, d4, d5], [b2, b3, b4, b6, b8]); } }" @@ -142,13 +142,13 @@ exports[`misc global 4`] = ` return function template(ctx, node, key = \\"\\") { ctx = Object.create(ctx); ctx = Object.create(ctx); - const [k2, v2, l2, c2] = prepareList([4,5,6]); - for (let i1 = 0; i1 < l2; i1++) { - ctx[\`value\`] = v2[i1]; + const [k_block2, v_block2, l_block2, c_block2] = prepareList([4,5,6]); + for (let i1 = 0; i1 < l_block2; i1++) { + ctx[\`value\`] = v_block2[i1]; ctx[\`value_first\`] = i1 === 0; - ctx[\`value_last\`] = i1 === v2.length - 1; + ctx[\`value_last\`] = i1 === v_block2.length - 1; ctx[\`value_index\`] = i1; - ctx[\`value_value\`] = k2[i1]; + ctx[\`value_value\`] = k_block2[i1]; let key1 = ctx['value']; let d1 = ctx['value']; let b4 = block4([d1]); @@ -164,10 +164,10 @@ exports[`misc global 4`] = ` ctx[zero] = b5; let b9 = callTemplate_8(ctx, node, key + \`__7__\${key1}\`); ctx = ctx.__proto__; - c2[i1] = withKey(multi([b4, b9]), key1); + c_block2[i1] = withKey(multi([b4, b9]), key1); } ctx = ctx.__proto__; - let b2 = list(c2); + let b2 = list(c_block2); let b10 = callTemplate_10(ctx, node, key + \`__9\`); return block1([], [b2, b10]); } @@ -216,17 +216,17 @@ exports[`misc other complex template 1`] = ` let d1 = \`/runbot/\${ctx['project'].slug}\`; let d2 = ctx['project'].name; ctx = Object.create(ctx); - const [k2, v2, l2, c2] = prepareList(ctx['projects']); - for (let i1 = 0; i1 < l2; i1++) { - ctx[\`project\`] = v2[i1]; + const [k_block2, v_block2, l_block2, c_block2] = prepareList(ctx['projects']); + for (let i1 = 0; i1 < l_block2; i1++) { + ctx[\`project\`] = v_block2[i1]; let key1 = ctx['project'].id; const arg1 = [ctx['project']]; let d3 = [ctx, 'selectProject', arg1]; let d4 = ctx['project'].name; - c2[i1] = withKey(block3([d3, d4]), key1); + c_block2[i1] = withKey(block3([d3, d4]), key1); } ctx = ctx.__proto__; - b2 = list(c2); + b2 = list(c_block2); if (ctx['user']) { let b5,b6; if (ctx['user'].public) { @@ -257,17 +257,17 @@ exports[`misc other complex template 1`] = ` let d12 = [ctx, 'toggleMore']; if (ctx['categories']&&ctx['categories'].length>1) { ctx = Object.create(ctx); - const [k15, v15, l15, c15] = prepareList(ctx['categories']); - for (let i1 = 0; i1 < l15; i1++) { - ctx[\`category\`] = v15[i1]; + const [k_block15, v_block15, l_block15, c_block15] = prepareList(ctx['categories']); + for (let i1 = 0; i1 < l_block15; i1++) { + ctx[\`category\`] = v_block15[i1]; let key1 = ctx['category'].id; let d13 = ctx['category'].id; let d14 = ctx['category'].id==ctx['options'].active_category_id; let d15 = ctx['category'].name; - c15[i1] = withKey(block16([d13, d14, d15]), key1); + c_block15[i1] = withKey(block16([d13, d14, d15]), key1); } ctx = ctx.__proto__; - let b15 = list(c15); + let b15 = list(c_block15); b14 = block14([], [b15]); } let d16 = ctx['search'].value; @@ -278,9 +278,9 @@ exports[`misc other complex template 1`] = ` let d21 = (el) => refs[\`settings_menu\`] = el; if (ctx['triggers']) { ctx = Object.create(ctx); - const [k18, v18, l18, c18] = prepareList(ctx['triggers']); - for (let i1 = 0; i1 < l18; i1++) { - ctx[\`trigger\`] = v18[i1]; + const [k_block18, v_block18, l_block18, c_block18] = prepareList(ctx['triggers']); + for (let i1 = 0; i1 < l_block18; i1++) { + ctx[\`trigger\`] = v_block18[i1]; let key1 = ctx['trigger'].id; let b20; if (!ctx['trigger'].manual&&ctx['trigger'].project_id===ctx['project'].id&&ctx['trigger'].category_id===ctx['options'].active_category_id) { @@ -293,10 +293,10 @@ exports[`misc other complex template 1`] = ` let d28 = ctx['trigger'].name; b20 = block20([d22, d23, d24, d25, d26, d27, d28]); } - c18[i1] = withKey(multi([b20]), key1); + c_block18[i1] = withKey(multi([b20]), key1); } ctx = ctx.__proto__; - let b18 = list(c18); + let b18 = list(c_block18); let d29 = [ctx, 'triggerAll']; let d30 = [ctx, 'triggerNone']; let d31 = [ctx, 'triggerDefault']; diff --git a/tests/qweb/__snapshots__/t_call.test.ts.snap b/tests/qweb/__snapshots__/t_call.test.ts.snap index 7ce3b1f6..86d9782a 100644 --- a/tests/qweb/__snapshots__/t_call.test.ts.snap +++ b/tests/qweb/__snapshots__/t_call.test.ts.snap @@ -384,20 +384,20 @@ exports[`t-call (template calling) recursive template, part 2 2`] = ` ctx = Object.create(ctx); let d1 = ctx['node'].val; ctx = Object.create(ctx); - const [k2, v2, l2, c2] = prepareList(ctx['node'].children||[]); - for (let i1 = 0; i1 < l2; i1++) { - ctx[\`subtree\`] = v2[i1]; + const [k_block2, v_block2, l_block2, c_block2] = prepareList(ctx['node'].children||[]); + for (let i1 = 0; i1 < l_block2; i1++) { + ctx[\`subtree\`] = v_block2[i1]; ctx[\`subtree_first\`] = i1 === 0; - ctx[\`subtree_last\`] = i1 === v2.length - 1; + ctx[\`subtree_last\`] = i1 === v_block2.length - 1; ctx[\`subtree_index\`] = i1; - ctx[\`subtree_value\`] = k2[i1]; + ctx[\`subtree_value\`] = k_block2[i1]; let key1 = ctx['subtree_index']; ctx = Object.create(ctx); ctx[\`node\`] = ctx['subtree']; - c2[i1] = withKey(callTemplate_2(ctx, node, key + \`__1__\${key1}\`), key1); + c_block2[i1] = withKey(callTemplate_2(ctx, node, key + \`__1__\${key1}\`), key1); ctx = ctx.__proto__; } - let b2 = list(c2); + let b2 = list(c_block2); return block1([d1], [b2]); } }" @@ -435,20 +435,20 @@ exports[`t-call (template calling) recursive template, part 3 2`] = ` ctx = Object.create(ctx); let d1 = ctx['node'].val; ctx = Object.create(ctx); - const [k2, v2, l2, c2] = prepareList(ctx['node'].children||[]); - for (let i1 = 0; i1 < l2; i1++) { - ctx[\`subtree\`] = v2[i1]; + const [k_block2, v_block2, l_block2, c_block2] = prepareList(ctx['node'].children||[]); + for (let i1 = 0; i1 < l_block2; i1++) { + ctx[\`subtree\`] = v_block2[i1]; ctx[\`subtree_first\`] = i1 === 0; - ctx[\`subtree_last\`] = i1 === v2.length - 1; + ctx[\`subtree_last\`] = i1 === v_block2.length - 1; ctx[\`subtree_index\`] = i1; - ctx[\`subtree_value\`] = k2[i1]; + ctx[\`subtree_value\`] = k_block2[i1]; let key1 = ctx['subtree_index']; ctx = Object.create(ctx); ctx[\`node\`] = ctx['subtree']; - c2[i1] = withKey(callTemplate_2(ctx, node, key + \`__1__\${key1}\`), key1); + c_block2[i1] = withKey(callTemplate_2(ctx, node, key + \`__1__\${key1}\`), key1); ctx = ctx.__proto__; } - let b2 = list(c2); + let b2 = list(c_block2); return block1([d1], [b2]); } }" @@ -489,20 +489,20 @@ exports[`t-call (template calling) recursive template, part 4: with t-set recurs let d1 = ctx['node'].val; let d2 = ctx['recursive_idx']; ctx = Object.create(ctx); - const [k2, v2, l2, c2] = prepareList(ctx['node'].children||[]); - for (let i1 = 0; i1 < l2; i1++) { - ctx[\`subtree\`] = v2[i1]; + const [k_block2, v_block2, l_block2, c_block2] = prepareList(ctx['node'].children||[]); + for (let i1 = 0; i1 < l_block2; i1++) { + ctx[\`subtree\`] = v_block2[i1]; ctx[\`subtree_first\`] = i1 === 0; - ctx[\`subtree_last\`] = i1 === v2.length - 1; + ctx[\`subtree_last\`] = i1 === v_block2.length - 1; ctx[\`subtree_index\`] = i1; - ctx[\`subtree_value\`] = k2[i1]; + ctx[\`subtree_value\`] = k_block2[i1]; let key1 = ctx['subtree_index']; ctx = Object.create(ctx); ctx[\`node\`] = ctx['subtree']; - c2[i1] = withKey(callTemplate_2(ctx, node, key + \`__1__\${key1}\`), key1); + c_block2[i1] = withKey(callTemplate_2(ctx, node, key + \`__1__\${key1}\`), key1); ctx = ctx.__proto__; } - let b2 = list(c2); + let b2 = list(c_block2); return block1([d1, d2], [b2]); } }" @@ -717,21 +717,21 @@ exports[`t-call (template calling) t-call with t-set inside and outside 1`] = ` return function template(ctx, node, key = \\"\\") { ctx = Object.create(ctx); ctx = Object.create(ctx); - const [k2, v2, l2, c2] = prepareList(ctx['list']); - for (let i1 = 0; i1 < l2; i1++) { - ctx[\`v\`] = v2[i1]; + const [k_block2, v_block2, l_block2, c_block2] = prepareList(ctx['list']); + for (let i1 = 0; i1 < l_block2; i1++) { + ctx[\`v\`] = v_block2[i1]; ctx[\`v_first\`] = i1 === 0; - ctx[\`v_last\`] = i1 === v2.length - 1; + ctx[\`v_last\`] = i1 === v_block2.length - 1; ctx[\`v_index\`] = i1; - ctx[\`v_value\`] = k2[i1]; + ctx[\`v_value\`] = k_block2[i1]; let key1 = ctx['v_index']; ctx[\`val\`] = ctx['v'].val; ctx = Object.create(ctx); ctx[\`val3\`] = ctx['val']*3; - c2[i1] = withKey(callTemplate_2(ctx, node, key + \`__1__\${key1}\`), key1); + c_block2[i1] = withKey(callTemplate_2(ctx, node, key + \`__1__\${key1}\`), key1); ctx = ctx.__proto__; } - let b2 = list(c2); + let b2 = list(c_block2); return block1([], [b2]); } }" @@ -764,21 +764,21 @@ exports[`t-call (template calling) t-call with t-set inside and outside. 2 1`] = return function template(ctx, node, key = \\"\\") { ctx = Object.create(ctx); ctx = Object.create(ctx); - const [k2, v2, l2, c2] = prepareList(ctx['list']); - for (let i1 = 0; i1 < l2; i1++) { - ctx[\`v\`] = v2[i1]; + const [k_block2, v_block2, l_block2, c_block2] = prepareList(ctx['list']); + for (let i1 = 0; i1 < l_block2; i1++) { + ctx[\`v\`] = v_block2[i1]; ctx[\`v_first\`] = i1 === 0; - ctx[\`v_last\`] = i1 === v2.length - 1; + ctx[\`v_last\`] = i1 === v_block2.length - 1; ctx[\`v_index\`] = i1; - ctx[\`v_value\`] = k2[i1]; + ctx[\`v_value\`] = k_block2[i1]; let key1 = ctx['v_index']; ctx[\`val\`] = ctx['v'].val; ctx = Object.create(ctx); ctx[\`val3\`] = ctx['val']*3; - c2[i1] = withKey(callTemplate_2(ctx, node, key + \`__1__\${key1}\`), key1); + c_block2[i1] = withKey(callTemplate_2(ctx, node, key + \`__1__\${key1}\`), key1); ctx = ctx.__proto__; } - let b2 = list(c2); + let b2 = list(c_block2); return block1([], [b2]); } }" diff --git a/tests/qweb/__snapshots__/t_foreach.test.ts.snap b/tests/qweb/__snapshots__/t_foreach.test.ts.snap index 5a377cd3..eeabc2e6 100644 --- a/tests/qweb/__snapshots__/t_foreach.test.ts.snap +++ b/tests/qweb/__snapshots__/t_foreach.test.ts.snap @@ -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]); } }" diff --git a/tests/qweb/__snapshots__/t_ref.test.ts.snap b/tests/qweb/__snapshots__/t_ref.test.ts.snap index 35a3e78b..8ad70a95 100644 --- a/tests/qweb/__snapshots__/t_ref.test.ts.snap +++ b/tests/qweb/__snapshots__/t_ref.test.ts.snap @@ -98,16 +98,16 @@ exports[`t-ref refs in a loop 1`] = ` return function template(ctx, node, key = \\"\\") { const refs = ctx.__owl__.refs; 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']; const v1 = ctx['item']; let d1 = (el) => refs[\`\${v1}\`] = el; let d2 = ctx['item']; - c2[i1] = withKey(block3([d1, d2]), key1); + c_block2[i1] = withKey(block3([d1, d2]), key1); } - let b2 = list(c2); + let b2 = list(c_block2); return block1([], [b2]); } }" diff --git a/tests/qweb/__snapshots__/t_set.test.ts.snap b/tests/qweb/__snapshots__/t_set.test.ts.snap index 09a422cd..630fa956 100644 --- a/tests/qweb/__snapshots__/t_set.test.ts.snap +++ b/tests/qweb/__snapshots__/t_set.test.ts.snap @@ -204,16 +204,16 @@ exports[`t-set t-set should reuse variable if possible 1`] = ` ctx = Object.create(ctx); ctx[\`v\`] = 1; ctx = Object.create(ctx); - const [k2, v2, l2, c2] = prepareList(ctx['list']); - for (let i1 = 0; i1 < l2; i1++) { - ctx[\`elem\`] = v2[i1]; + const [k_block2, v_block2, l_block2, c_block2] = prepareList(ctx['list']); + for (let i1 = 0; i1 < l_block2; i1++) { + ctx[\`elem\`] = v_block2[i1]; ctx[\`elem_index\`] = i1; let key1 = ctx['elem_index']; let d1 = ctx['v']; ctx[\`v\`] = ctx['elem']; - 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]); } }"