[FIX] qweb: variables set outside foreach must be altered by inloop t-tset

In a template, have t-set t-value outside a t-foreach
in the t-foreach, alter that variable by resetting it (as for a incrementation variable)

Before this commit, when printing the variable when the loop had finished
its value was the one set in the first place

After this commit, the value becomes the one altered by the loop iterations

closes #598
This commit is contained in:
Lucas Perais (lpe)
2020-01-02 14:01:45 +01:00
committed by Géry Debongnie
parent 23012f3e7c
commit 21737d33fa
7 changed files with 542 additions and 44 deletions
@@ -58,7 +58,7 @@ exports[`basic widget properties reconciliation alg works for t-foreach in t-for
}
let _length3 = _3.length;
let _origScope5 = scope;
scope = Object.assign(Object.create(context), scope);
scope = Object.create(scope);
for (let i1 = 0; i1 < _length3; i1++) {
scope.section_first = i1 === 0
scope.section_last = i1 === _length3 - 1
@@ -75,7 +75,7 @@ exports[`basic widget properties reconciliation alg works for t-foreach in t-for
}
let _length7 = _7.length;
let _origScope9 = scope;
scope = Object.assign(Object.create(context), scope);
scope = Object.create(scope);
for (let i2 = 0; i2 < _length7; i2++) {
scope.blip_first = i2 === 0
scope.blip_last = i2 === _length7 - 1
@@ -432,7 +432,7 @@ exports[`composition sub components with some state rendered in a loop 1`] = `
}
let _length3 = _3.length;
let _origScope5 = scope;
scope = Object.assign(Object.create(context), scope);
scope = Object.create(scope);
for (let i1 = 0; i1 < _length3; i1++) {
scope.number_first = i1 === 0
scope.number_last = i1 === _length3 - 1
@@ -587,6 +587,58 @@ exports[`dynamic t-props basic use 1`] = `
}"
`;
exports[`other directives with t-component slot setted value (with t-set) not accessible with t-esc 1`] = `
"function anonymous(context, extra
) {
// Template name: \\"__template__2\\"
let utils = this.constructor.utils;
let QWeb = this.constructor;
let parent = context;
let scope = Object.create(context);
let h = this.h;
let c1 = [], p1 = {key:1};
let vn1 = h('div', p1, c1);
scope.iter = 'source';
let c2 = [], p2 = {key:2};
let vn2 = h('p', p2, c2);
c1.push(vn2);
if (scope.iter != null) {
c2.push({text: scope.iter});
}
// Component 'ChildWidget'
let w3 = '__4__' in parent.__owl__.cmap ? parent.__owl__.children[parent.__owl__.cmap['__4__']] : false;
let props3 = {};
if (w3 && w3.__owl__.currentFiber && !w3.__owl__.vnode) {
w3.destroy();
w3 = false;
}
if (w3) {
w3.__updateProps(props3, extra.fiber, Object.assign(Object.create(context), scope));
let pvnode = w3.__owl__.pvnode;
c1.push(pvnode);
} else {
let componentKey3 = \`ChildWidget\`;
let W3 = context.constructor.components[componentKey3] || QWeb.components[componentKey3]|| scope['ChildWidget'];
if (!W3) {throw new Error('Cannot find the definition of component \\"' + componentKey3 + '\\"')}
w3 = new W3(parent, props3);
parent.__owl__.cmap['__4__'] = w3.__owl__.id;
w3.__owl__.slotId = 1;
let fiber = w3.__prepare(extra.fiber, Object.assign(Object.create(context), scope), () => { const vnode = fiber.vnode; pvnode.sel = vnode.sel; });
let pvnode = h('dummy', {key: '__4__', hook: {remove() {},destroy(vn) {w3.destroy();}}});
c1.push(pvnode);
w3.__owl__.pvnode = pvnode;
}
w3.__owl__.parentLastFiberId = extra.fiber.id;
let c5 = [], p5 = {key:5};
let vn5 = h('p', p5, c5);
c1.push(vn5);
if (scope.iter != null) {
c5.push({text: scope.iter});
}
return vn1;
}"
`;
exports[`other directives with t-component t-on with getter as handler 1`] = `
"function anonymous(context, extra
) {
@@ -1017,6 +1069,195 @@ exports[`other directives with t-component t-on with stop and/or prevent modifie
}"
`;
exports[`other directives with t-component t-set can't alter component 1`] = `
"function anonymous(context, extra
) {
// Template name: \\"__template__1\\"
let scope = Object.create(context);
let h = this.h;
let c1 = [], p1 = {key:1};
let vn1 = h('div', p1, c1);
let c2 = [], p2 = {key:2};
let vn2 = h('p', p2, c2);
c1.push(vn2);
let _3 = scope['iter'];
if (_3 != null) {
c2.push({text: _3});
}
scope.iter = 5;
let c4 = [], p4 = {key:4};
let vn4 = h('p', p4, c4);
c1.push(vn4);
if (scope.iter != null) {
c4.push({text: scope.iter});
}
return vn1;
}"
`;
exports[`other directives with t-component t-set can't alter from within callee 1`] = `
"function anonymous(context, extra
) {
// Template name: \\"__template__1\\"
let utils = this.constructor.utils;
let scope = Object.create(context);
let h = this.h;
let c1 = [], p1 = {key:1};
let vn1 = h('div', p1, c1);
scope.iter = 'source';
let c2 = [], p2 = {key:2};
let vn2 = h('p', p2, c2);
c1.push(vn2);
if (scope.iter != null) {
c2.push({text: scope.iter});
}
this.subTemplates['ChildWidget'].call(this, Object.assign(Object.create(context), scope), Object.assign({}, extra, {parentNode: c1, parent: utils.getComponent(context)}));
let c4 = [], p4 = {key:4};
let vn4 = h('p', p4, c4);
c1.push(vn4);
if (scope.iter != null) {
c4.push({text: scope.iter});
}
return vn1;
}"
`;
exports[`other directives with t-component t-set can't alter in t-call body 1`] = `
"function anonymous(context, extra
) {
// Template name: \\"__template__1\\"
let utils = this.constructor.utils;
let scope = Object.create(context);
let h = this.h;
let c1 = [], p1 = {key:1};
let vn1 = h('div', p1, c1);
scope.iter = 'source';
let c2 = [], p2 = {key:2};
let vn2 = h('p', p2, c2);
c1.push(vn2);
if (scope.iter != null) {
c2.push({text: scope.iter});
}
{
let _origScope4 = scope;
scope = Object.assign(Object.create(context), scope);
{
let c__0 = [];
utils.getScope(scope, 'iter').iter = 'inCall';
scope[utils.zero] = c__0;
}
this.subTemplates['ChildWidget'].call(this, scope, Object.assign({}, extra, {parentNode: c1, parent: utils.getComponent(context)}));
scope = _origScope4;
}
let c5 = [], p5 = {key:5};
let vn5 = h('p', p5, c5);
c1.push(vn5);
if (scope.iter != null) {
c5.push({text: scope.iter});
}
return vn1;
}"
`;
exports[`other directives with t-component t-set not altered by child widget 1`] = `
"function anonymous(context, extra
) {
// Template name: \\"__template__2\\"
let utils = this.constructor.utils;
let QWeb = this.constructor;
let parent = context;
let scope = Object.create(context);
let h = this.h;
let c1 = [], p1 = {key:1};
let vn1 = h('div', p1, c1);
scope.iter = 'source';
let c2 = [], p2 = {key:2};
let vn2 = h('p', p2, c2);
c1.push(vn2);
if (scope.iter != null) {
c2.push({text: scope.iter});
}
// Component 'ChildWidget'
let w3 = '__4__' in parent.__owl__.cmap ? parent.__owl__.children[parent.__owl__.cmap['__4__']] : false;
let props3 = {};
if (w3 && w3.__owl__.currentFiber && !w3.__owl__.vnode) {
w3.destroy();
w3 = false;
}
if (w3) {
w3.__updateProps(props3, extra.fiber, undefined);
let pvnode = w3.__owl__.pvnode;
c1.push(pvnode);
} else {
let componentKey3 = \`ChildWidget\`;
let W3 = context.constructor.components[componentKey3] || QWeb.components[componentKey3]|| scope['ChildWidget'];
if (!W3) {throw new Error('Cannot find the definition of component \\"' + componentKey3 + '\\"')}
w3 = new W3(parent, props3);
parent.__owl__.cmap['__4__'] = w3.__owl__.id;
let fiber = w3.__prepare(extra.fiber, undefined, () => { const vnode = fiber.vnode; pvnode.sel = vnode.sel; });
let pvnode = h('dummy', {key: '__4__', hook: {remove() {},destroy(vn) {w3.destroy();}}});
c1.push(pvnode);
w3.__owl__.pvnode = pvnode;
}
w3.__owl__.parentLastFiberId = extra.fiber.id;
let c5 = [], p5 = {key:5};
let vn5 = h('p', p5, c5);
c1.push(vn5);
if (scope.iter != null) {
c5.push({text: scope.iter});
}
return vn1;
}"
`;
exports[`other directives with t-component t-set outside modified in t-foreach 1`] = `
"function anonymous(context, extra
) {
// Template name: \\"__template__1\\"
let utils = this.constructor.utils;
let scope = Object.create(context);
let h = this.h;
let c1 = [], p1 = {key:1};
let vn1 = h('div', p1, c1);
scope.iter = 0;
let _2 = scope['state'].values;
if (!_2) { throw new Error('QWeb error: Invalid loop expression')}
let _3 = _4 = _2;
if (!(_2 instanceof Array)) {
_3 = Object.keys(_2);
_4 = Object.values(_2);
}
let _length3 = _3.length;
let _origScope5 = scope;
scope = Object.create(scope);
for (let i1 = 0; i1 < _length3; i1++) {
scope.val_first = i1 === 0
scope.val_last = i1 === _length3 - 1
scope.val_index = i1
scope.val = _3[i1]
scope.val_value = _4[i1]
let key1 = scope['val'];
let c6 = [], p6 = {key:\`\${key1}_6\`};
let vn6 = h('p', p6, c6);
c1.push(vn6);
c6.push({text: \`InLoop: \`});
if (scope.iter != null) {
c6.push({text: scope.iter});
}
utils.getScope(scope, 'iter').iter = scope.iter+1;
}
scope = _origScope5;
let c7 = [], p7 = {key:7};
let vn7 = h('p', p7, c7);
c1.push(vn7);
c7.push({text: \`EndLoop: \`});
if (scope.iter != null) {
c7.push({text: scope.iter});
}
return vn1;
}"
`;
exports[`random stuff/miscellaneous can inject values in tagged templates 1`] = `
"function anonymous(context, extra
) {
@@ -1093,7 +1334,7 @@ exports[`random stuff/miscellaneous t-on with handler bound to dynamic argument
}
let _length3 = _3.length;
let _origScope5 = scope;
scope = Object.assign(Object.create(context), scope);
scope = Object.create(scope);
for (let i1 = 0; i1 < _length3; i1++) {
scope.item_first = i1 === 0
scope.item_last = i1 === _length3 - 1
@@ -1342,7 +1583,7 @@ exports[`t-model directive in a t-foreach 1`] = `
}
let _length3 = _3.length;
let _origScope5 = scope;
scope = Object.assign(Object.create(context), scope);
scope = Object.create(scope);
for (let i1 = 0; i1 < _length3; i1++) {
scope.thing_first = i1 === 0
scope.thing_last = i1 === _length3 - 1