[REF] qweb: t-foreach: remove integer support for t-value

Handling it complexifies the compiled code, and it is not really
useful (the same result can be achieved with t-foreach="Array(n)")

Part of #128
This commit is contained in:
Aaron Bohy
2019-06-07 14:10:59 +02:00
committed by Géry Debongnie
parent b14d069ee7
commit 49baf0de6e
6 changed files with 75 additions and 127 deletions
+55 -73
View File
@@ -317,10 +317,12 @@ exports[`foreach does not pollute the rendering context 1`] = `
var vn1 = h('div', p1, c1);
var _2 = [1];
if (!_2) { throw new Error('QWeb error: Invalid loop expression')}
if (typeof _2 === 'number') { _2 = Array.from(Array(_2).keys())}
var _3 = _2 instanceof Array ? _2 : Object.keys(_2);
var _3 = _4 = _2;
if (!(_2 instanceof Array)) {
_3 = Object.keys(_2);
_4 = Object.values(_2);
}
var _length3 = _3.length;
var _4 = _2 instanceof Array ? _2 : Object.values(_2);
for (let i = 0; i < _length3; i++) {
context.item_first = i === 0;
context.item_last = i === _length3 - 1;
@@ -345,10 +347,12 @@ exports[`foreach iterate on items (on a element node) 1`] = `
var vn1 = h('div', p1, c1);
var _2 = [1, 2];
if (!_2) { throw new Error('QWeb error: Invalid loop expression')}
if (typeof _2 === 'number') { _2 = Array.from(Array(_2).keys())}
var _3 = _2 instanceof Array ? _2 : Object.keys(_2);
var _3 = _4 = _2;
if (!(_2 instanceof Array)) {
_3 = Object.keys(_2);
_4 = Object.values(_2);
}
var _length3 = _3.length;
var _4 = _2 instanceof Array ? _2 : Object.values(_2);
for (let i = 0; i < _length3; i++) {
context.item_first = i === 0;
context.item_last = i === _length3 - 1;
@@ -376,10 +380,12 @@ exports[`foreach iterate on items 1`] = `
var vn1 = h('div', p1, c1);
var _2 = [3, 2, 1];
if (!_2) { throw new Error('QWeb error: Invalid loop expression')}
if (typeof _2 === 'number') { _2 = Array.from(Array(_2).keys())}
var _3 = _2 instanceof Array ? _2 : Object.keys(_2);
var _3 = _4 = _2;
if (!(_2 instanceof Array)) {
_3 = Object.keys(_2);
_4 = Object.values(_2);
}
var _length3 = _3.length;
var _4 = _2 instanceof Array ? _2 : Object.values(_2);
for (let i = 0; i < _length3; i++) {
context.item_first = i === 0;
context.item_last = i === _length3 - 1;
@@ -416,50 +422,12 @@ exports[`foreach iterate, dict param 1`] = `
var vn1 = h('div', p1, c1);
var _2 = context['value'];
if (!_2) { throw new Error('QWeb error: Invalid loop expression')}
if (typeof _2 === 'number') { _2 = Array.from(Array(_2).keys())}
var _3 = _2 instanceof Array ? _2 : Object.keys(_2);
var _length3 = _3.length;
var _4 = _2 instanceof Array ? _2 : Object.values(_2);
for (let i = 0; i < _length3; i++) {
context.item_first = i === 0;
context.item_last = i === _length3 - 1;
context.item_index = i;
context.item = _3[i];
context.item_value = _4[i];
c1.push({text: \` [\`});
var _5 = context['item_index'];
if (_5 || _5 === 0) {
c1.push({text: _5});
}
c1.push({text: \`: \`});
var _6 = context['item'];
if (_6 || _6 === 0) {
c1.push({text: _6});
}
c1.push({text: \` \`});
var _7 = context['item_value'];
if (_7 || _7 === 0) {
c1.push({text: _7});
}
c1.push({text: \`] \`});
var _3 = _4 = _2;
if (!(_2 instanceof Array)) {
_3 = Object.keys(_2);
_4 = Object.values(_2);
}
return vn1;
}"
`;
exports[`foreach iterate, integer param 1`] = `
"function anonymous(context,extra
) {
context = Object.create(context);
var h = this.utils.h;
let c1 = [], p1 = {key:1};
var vn1 = h('div', p1, c1);
var _2 = 3;
if (!_2) { throw new Error('QWeb error: Invalid loop expression')}
if (typeof _2 === 'number') { _2 = Array.from(Array(_2).keys())}
var _3 = _2 instanceof Array ? _2 : Object.keys(_2);
var _length3 = _3.length;
var _4 = _2 instanceof Array ? _2 : Object.values(_2);
for (let i = 0; i < _length3; i++) {
context.item_first = i === 0;
context.item_last = i === _length3 - 1;
@@ -494,12 +462,14 @@ exports[`foreach iterate, position 1`] = `
var h = this.utils.h;
let c1 = [], p1 = {key:1};
var vn1 = h('div', p1, c1);
var _2 = 5;
var _2 = Array(5);
if (!_2) { throw new Error('QWeb error: Invalid loop expression')}
if (typeof _2 === 'number') { _2 = Array.from(Array(_2).keys())}
var _3 = _2 instanceof Array ? _2 : Object.keys(_2);
var _3 = _4 = _2;
if (!(_2 instanceof Array)) {
_3 = Object.keys(_2);
_4 = Object.values(_2);
}
var _length3 = _3.length;
var _4 = _2 instanceof Array ? _2 : Object.values(_2);
for (let i = 0; i < _length3; i++) {
context.elem_first = i === 0;
context.elem_last = i === _length3 - 1;
@@ -533,10 +503,12 @@ exports[`foreach warn if no key in some case 1`] = `
var vn1 = h('div', p1, c1);
var _2 = [1, 2];
if (!_2) { throw new Error('QWeb error: Invalid loop expression')}
if (typeof _2 === 'number') { _2 = Array.from(Array(_2).keys())}
var _3 = _2 instanceof Array ? _2 : Object.keys(_2);
var _3 = _4 = _2;
if (!(_2 instanceof Array)) {
_3 = Object.keys(_2);
_4 = Object.values(_2);
}
var _length3 = _3.length;
var _4 = _2 instanceof Array ? _2 : Object.values(_2);
for (let i = 0; i < _length3; i++) {
context.item_first = i === 0;
context.item_last = i === _length3 - 1;
@@ -593,10 +565,12 @@ exports[`misc global 1`] = `
var vn1 = h('div', p1, c1);
var _2 = [4,5,6];
if (!_2) { throw new Error('QWeb error: Invalid loop expression')}
if (typeof _2 === 'number') { _2 = Array.from(Array(_2).keys())}
var _3 = _2 instanceof Array ? _2 : Object.keys(_2);
var _3 = _4 = _2;
if (!(_2 instanceof Array)) {
_3 = Object.keys(_2);
_4 = Object.values(_2);
}
var _length3 = _3.length;
var _4 = _2 instanceof Array ? _2 : Object.values(_2);
for (let i = 0; i < _length3; i++) {
context.value_first = i === 0;
context.value_last = i === _length3 - 1;
@@ -1102,10 +1076,12 @@ exports[`t-key t-key directive in a list 1`] = `
var vn1 = h('ul', p1, c1);
var _2 = context['beers'];
if (!_2) { throw new Error('QWeb error: Invalid loop expression')}
if (typeof _2 === 'number') { _2 = Array.from(Array(_2).keys())}
var _3 = _2 instanceof Array ? _2 : Object.keys(_2);
var _3 = _4 = _2;
if (!(_2 instanceof Array)) {
_3 = Object.keys(_2);
_4 = Object.values(_2);
}
var _length3 = _3.length;
var _4 = _2 instanceof Array ? _2 : Object.values(_2);
for (let i = 0; i < _length3; i++) {
context.beer_first = i === 0;
context.beer_last = i === _length3 - 1;
@@ -1201,10 +1177,12 @@ exports[`t-on can bind handlers with loop variable as argument 1`] = `
var vn1 = h('ul', p1, c1);
var _2 = ['someval'];
if (!_2) { throw new Error('QWeb error: Invalid loop expression')}
if (typeof _2 === 'number') { _2 = Array.from(Array(_2).keys())}
var _3 = _2 instanceof Array ? _2 : Object.keys(_2);
var _3 = _4 = _2;
if (!(_2 instanceof Array)) {
_3 = Object.keys(_2);
_4 = Object.values(_2);
}
var _length3 = _3.length;
var _4 = _2 instanceof Array ? _2 : Object.values(_2);
for (let i = 0; i < _length3; i++) {
context.action_first = i === 0;
context.action_last = i === _length3 - 1;
@@ -1528,10 +1506,12 @@ exports[`t-ref refs in a loop 1`] = `
var vn1 = h('div', p1, c1);
var _2 = context['items'];
if (!_2) { throw new Error('QWeb error: Invalid loop expression')}
if (typeof _2 === 'number') { _2 = Array.from(Array(_2).keys())}
var _3 = _2 instanceof Array ? _2 : Object.keys(_2);
var _3 = _4 = _2;
if (!(_2 instanceof Array)) {
_3 = Object.keys(_2);
_4 = Object.values(_2);
}
var _length3 = _3.length;
var _4 = _2 instanceof Array ? _2 : Object.values(_2);
for (let i = 0; i < _length3; i++) {
context.item_first = i === 0;
context.item_last = i === _length3 - 1;
@@ -1686,10 +1666,12 @@ exports[`t-set t-set should reuse variable if possible 1`] = `
var _2 = 1;
var _3 = context['list'];
if (!_3) { throw new Error('QWeb error: Invalid loop expression')}
if (typeof _3 === 'number') { _3 = Array.from(Array(_3).keys())}
var _4 = _3 instanceof Array ? _3 : Object.keys(_3);
var _4 = _5 = _3;
if (!(_3 instanceof Array)) {
_4 = Object.keys(_3);
_5 = Object.values(_3);
}
var _length4 = _4.length;
var _5 = _3 instanceof Array ? _3 : Object.values(_3);
for (let i = 0; i < _length4; i++) {
context.elem_first = i === 0;
context.elem_last = i === _length4 - 1;