Files
owl/tests/__snapshots__/qweb.test.ts.snap
T
Géry Debongnie a7d2edd0c9 imp: qweb compiler now condenses whitespaces
This is a pretty big breaking change: the html output by qweb is now
different.

The main goal is to optimize the compiled templates:
- condense all consecutive whitespaces into a single spaces
- if possible, drop completely some text nodes, based on the following
  heuristic: if a text node is only composed of whitespaces, and
contains at least one linebreak, then it can be dropped.

This leads in my benchmark test to an improvement of about 10%, in
rendering speed and in memory consuption.

Note: whitespace here means anything that matches the \s regexp: newlines,
tabs, ...

close #8
2019-03-22 12:04:50 +01:00

1361 lines
34 KiB
Plaintext

// Jest Snapshot v1, https://goo.gl/fbAQLP
exports[`attributes dynamic attribute falsy variable 1`] = `
"function anonymous(context,extra
) {
let h = this.utils.h;
let _1 = context['value'];
let c2 = [], p2 = {key:2,attrs:{foo: _1}};
let vn2 = h('div', p2, c2);
return vn2;
}"
`;
exports[`attributes dynamic attribute with a dash 1`] = `
"function anonymous(context,extra
) {
let h = this.utils.h;
let _1 = context['id'];
let c2 = [], p2 = {key:2,attrs:{\\"data-action-id\\": _1}};
let vn2 = h('div', p2, c2);
return vn2;
}"
`;
exports[`attributes dynamic attributes 1`] = `
"function anonymous(context,extra
) {
let h = this.utils.h;
let _1 = 'bar';
let c2 = [], p2 = {key:2,attrs:{foo: _1}};
let vn2 = h('div', p2, c2);
return vn2;
}"
`;
exports[`attributes dynamic formatted attributes with a dash 1`] = `
"function anonymous(context,extra
) {
let h = this.utils.h;
let _1 = \`Some text \${context['id']}\`;
let c2 = [], p2 = {key:2,attrs:{\\"aria-label\\": _1}};
let vn2 = h('div', p2, c2);
return vn2;
}"
`;
exports[`attributes fixed variable 1`] = `
"function anonymous(context,extra
) {
let h = this.utils.h;
let _1 = context['value'];
let c2 = [], p2 = {key:2,attrs:{foo: _1}};
let vn2 = h('div', p2, c2);
return vn2;
}"
`;
exports[`attributes format expression 1`] = `
"function anonymous(context,extra
) {
let h = this.utils.h;
let _1 = \`\${context['value'] + 37}\`;
let c2 = [], p2 = {key:2,attrs:{foo: _1}};
let vn2 = h('div', p2, c2);
return vn2;
}"
`;
exports[`attributes format literal 1`] = `
"function anonymous(context,extra
) {
let h = this.utils.h;
let _1 = \`bar\`;
let c2 = [], p2 = {key:2,attrs:{foo: _1}};
let vn2 = h('div', p2, c2);
return vn2;
}"
`;
exports[`attributes format multiple 1`] = `
"function anonymous(context,extra
) {
let h = this.utils.h;
let _1 = \`a \${context['value1']} is \${context['value2']} of \${context['value3']} ]\`;
let c2 = [], p2 = {key:2,attrs:{foo: _1}};
let vn2 = h('div', p2, c2);
return vn2;
}"
`;
exports[`attributes format value 1`] = `
"function anonymous(context,extra
) {
let h = this.utils.h;
let _1 = \`b\${context['value']}r\`;
let c2 = [], p2 = {key:2,attrs:{foo: _1}};
let vn2 = h('div', p2, c2);
return vn2;
}"
`;
exports[`attributes from object variables set previously 1`] = `
"function anonymous(context,extra
) {
let h = this.utils.h;
let c1 = [], p1 = {key:1};
let vn1 = h('div', p1, c1);
let _2 = {a:'b'}.a;
let c3 = [], p3 = {key:3,attrs:{class: _2}};
let vn3 = h('span', p3, c3);
c1.push(vn3);
return vn1;
}"
`;
exports[`attributes from variables set previously 1`] = `
"function anonymous(context,extra
) {
let h = this.utils.h;
let c1 = [], p1 = {key:1};
let vn1 = h('div', p1, c1);
let _2 = 'def';
let c3 = [], p3 = {key:3,attrs:{class: _2}};
let vn3 = h('span', p3, c3);
c1.push(vn3);
return vn1;
}"
`;
exports[`attributes object 1`] = `
"function anonymous(context,extra
) {
let h = this.utils.h;
let _1 = context['value'];
let c2 = [], p2 = {key:2,attrs:{}};
if (_1 instanceof Array) {
p2.attrs[_1[0]] = _1[1];
} else {
for (let key in _1) {
p2.attrs[key] = _1[key];
}
}
let vn2 = h('div', p2, c2);
return vn2;
}"
`;
exports[`attributes static attributes 1`] = `
"function anonymous(context,extra
) {
let h = this.utils.h;
let _1 = 'a';
let _2 = 'b';
let _3 = 'c';
let c4 = [], p4 = {key:4,attrs:{foo: _1,bar: _2,baz: _3}};
let vn4 = h('div', p4, c4);
return vn4;
}"
`;
exports[`attributes static attributes on void elements 1`] = `
"function anonymous(context,extra
) {
let h = this.utils.h;
let _1 = '/test.jpg';
let _2 = 'Test';
let c3 = [], p3 = {key:3,attrs:{src: _1,alt: _2}};
let vn3 = h('img', p3, c3);
return vn3;
}"
`;
exports[`attributes static attributes with dashes 1`] = `
"function anonymous(context,extra
) {
let h = this.utils.h;
let _1 = 'Close';
let c2 = [], p2 = {key:2,attrs:{\\"aria-label\\": _1}};
let vn2 = h('div', p2, c2);
return vn2;
}"
`;
exports[`attributes t-att-class and class should combine together 1`] = `
"function anonymous(context,extra
) {
let h = this.utils.h;
let _1 = 'hello';
let _3 = context['value'];
let _2 = 'hello' + (_3 ? ' ' + _3 : '');
let c4 = [], p4 = {key:4,attrs:{class: _2}};
let vn4 = h('div', p4, c4);
return vn4;
}"
`;
exports[`attributes t-att-class with object 1`] = `
"function anonymous(context,extra
) {
let h = this.utils.h;
let _1 = 'static';
let _3 = this.utils.objectToAttrString({a: context['b'],c: context['d'],e: context['f']});
let _2 = 'static' + (_3 ? ' ' + _3 : '');
let c4 = [], p4 = {key:4,attrs:{class: _2}};
let vn4 = h('div', p4, c4);
return vn4;
}"
`;
exports[`attributes tuple literal 1`] = `
"function anonymous(context,extra
) {
let h = this.utils.h;
let _1 = ['foo', 'bar'];
let c2 = [], p2 = {key:2,attrs:{}};
if (_1 instanceof Array) {
p2.attrs[_1[0]] = _1[1];
} else {
for (let key in _1) {
p2.attrs[key] = _1[key];
}
}
let vn2 = h('div', p2, c2);
return vn2;
}"
`;
exports[`attributes tuple variable 1`] = `
"function anonymous(context,extra
) {
let h = this.utils.h;
let _1 = context['value'];
let c2 = [], p2 = {key:2,attrs:{}};
if (_1 instanceof Array) {
p2.attrs[_1[0]] = _1[1];
} else {
for (let key in _1) {
p2.attrs[key] = _1[key];
}
}
let vn2 = h('div', p2, c2);
return vn2;
}"
`;
exports[`foreach does not pollute the rendering context 1`] = `
"function anonymous(context,extra
) {
context = Object.create(context);
let h = this.utils.h;
let c1 = [], p1 = {key:1};
let vn1 = h('div', p1, c1);
let _2 = [1];
if (!_2) { throw new Error('QWeb error: Invalid loop expression')}
if (typeof _2 === 'number') { _2 = Array.from(Array(_2).keys())}
let _3 = _2 instanceof Array ? _2 : Object.keys(_2);
let _4 = _2 instanceof Array ? _2 : Object.values(_2);
for (let i = 0; i < _3.length; i++) {
context.item_first = i === 0;
context.item_last = i === _3.length - 1;
context.item_parity = i % 2 === 0 ? 'even' : 'odd';
context.item_index = i;
context.item = _3[i];
context.item_value = _4[i];
let e5 = context['item'];
if (e5 || e5 === 0) {
c1.push({text: e5});
}
}
return vn1;
}"
`;
exports[`foreach iterate on items (on a element node) 1`] = `
"function anonymous(context,extra
) {
context = Object.create(context);
let h = this.utils.h;
let c1 = [], p1 = {key:1};
let vn1 = h('div', p1, c1);
let _2 = [1, 2];
if (!_2) { throw new Error('QWeb error: Invalid loop expression')}
if (typeof _2 === 'number') { _2 = Array.from(Array(_2).keys())}
let _3 = _2 instanceof Array ? _2 : Object.keys(_2);
let _4 = _2 instanceof Array ? _2 : Object.values(_2);
for (let i = 0; i < _3.length; i++) {
context.item_first = i === 0;
context.item_last = i === _3.length - 1;
context.item_parity = i % 2 === 0 ? 'even' : 'odd';
context.item_index = i;
context.item = _3[i];
context.item_value = _4[i];
let c5 = [], p5 = {key:5};
let vn5 = h('span', p5, c5);
c1.push(vn5);
let e6 = context['item'];
if (e6 || e6 === 0) {
c5.push({text: e6});
}
}
return vn1;
}"
`;
exports[`foreach iterate on items 1`] = `
"function anonymous(context,extra
) {
context = Object.create(context);
let h = this.utils.h;
let c1 = [], p1 = {key:1};
let vn1 = h('div', p1, c1);
let _2 = [3, 2, 1];
if (!_2) { throw new Error('QWeb error: Invalid loop expression')}
if (typeof _2 === 'number') { _2 = Array.from(Array(_2).keys())}
let _3 = _2 instanceof Array ? _2 : Object.keys(_2);
let _4 = _2 instanceof Array ? _2 : Object.values(_2);
for (let i = 0; i < _3.length; i++) {
context.item_first = i === 0;
context.item_last = i === _3.length - 1;
context.item_parity = i % 2 === 0 ? 'even' : 'odd';
context.item_index = i;
context.item = _3[i];
context.item_value = _4[i];
c1.push({text: \` [\`});
let e5 = context['item_index'];
if (e5 || e5 === 0) {
c1.push({text: e5});
}
c1.push({text: \`: \`});
let e6 = context['item'];
if (e6 || e6 === 0) {
c1.push({text: e6});
}
c1.push({text: \` \`});
let e7 = context['item_value'];
if (e7 || e7 === 0) {
c1.push({text: e7});
}
c1.push({text: \`] \`});
}
return vn1;
}"
`;
exports[`foreach iterate, dict param 1`] = `
"function anonymous(context,extra
) {
context = Object.create(context);
let h = this.utils.h;
let c1 = [], p1 = {key:1};
let vn1 = h('div', p1, c1);
let _2 = context['value'];
if (!_2) { throw new Error('QWeb error: Invalid loop expression')}
if (typeof _2 === 'number') { _2 = Array.from(Array(_2).keys())}
let _3 = _2 instanceof Array ? _2 : Object.keys(_2);
let _4 = _2 instanceof Array ? _2 : Object.values(_2);
for (let i = 0; i < _3.length; i++) {
context.item_first = i === 0;
context.item_last = i === _3.length - 1;
context.item_parity = i % 2 === 0 ? 'even' : 'odd';
context.item_index = i;
context.item = _3[i];
context.item_value = _4[i];
c1.push({text: \` [\`});
let e5 = context['item_index'];
if (e5 || e5 === 0) {
c1.push({text: e5});
}
c1.push({text: \`: \`});
let e6 = context['item'];
if (e6 || e6 === 0) {
c1.push({text: e6});
}
c1.push({text: \` \`});
let e7 = context['item_value'];
if (e7 || e7 === 0) {
c1.push({text: e7});
}
c1.push({text: \` - \`});
let e8 = context['item_parity'];
if (e8 || e8 === 0) {
c1.push({text: e8});
}
c1.push({text: \`] \`});
}
return vn1;
}"
`;
exports[`foreach iterate, integer param 1`] = `
"function anonymous(context,extra
) {
context = Object.create(context);
let h = this.utils.h;
let c1 = [], p1 = {key:1};
let vn1 = h('div', p1, c1);
let _2 = 3;
if (!_2) { throw new Error('QWeb error: Invalid loop expression')}
if (typeof _2 === 'number') { _2 = Array.from(Array(_2).keys())}
let _3 = _2 instanceof Array ? _2 : Object.keys(_2);
let _4 = _2 instanceof Array ? _2 : Object.values(_2);
for (let i = 0; i < _3.length; i++) {
context.item_first = i === 0;
context.item_last = i === _3.length - 1;
context.item_parity = i % 2 === 0 ? 'even' : 'odd';
context.item_index = i;
context.item = _3[i];
context.item_value = _4[i];
c1.push({text: \` [\`});
let e5 = context['item_index'];
if (e5 || e5 === 0) {
c1.push({text: e5});
}
c1.push({text: \`: \`});
let e6 = context['item'];
if (e6 || e6 === 0) {
c1.push({text: e6});
}
c1.push({text: \` \`});
let e7 = context['item_value'];
if (e7 || e7 === 0) {
c1.push({text: e7});
}
c1.push({text: \`] \`});
}
return vn1;
}"
`;
exports[`foreach iterate, position 1`] = `
"function anonymous(context,extra
) {
context = Object.create(context);
let h = this.utils.h;
let c1 = [], p1 = {key:1};
let vn1 = h('div', p1, c1);
let _2 = 5;
if (!_2) { throw new Error('QWeb error: Invalid loop expression')}
if (typeof _2 === 'number') { _2 = Array.from(Array(_2).keys())}
let _3 = _2 instanceof Array ? _2 : Object.keys(_2);
let _4 = _2 instanceof Array ? _2 : Object.values(_2);
for (let i = 0; i < _3.length; i++) {
context.elem_first = i === 0;
context.elem_last = i === _3.length - 1;
context.elem_parity = i % 2 === 0 ? 'even' : 'odd';
context.elem_index = i;
context.elem = _3[i];
context.elem_value = _4[i];
c1.push({text: \` -\`});
if (context['elem_first']) {
c1.push({text: \` first\`});
}
if (context['elem_last']) {
c1.push({text: \` last\`});
}
c1.push({text: \` (\`});
let e5 = context['elem_parity'];
if (e5 || e5 === 0) {
c1.push({text: e5});
}
c1.push({text: \`) \`});
}
return vn1;
}"
`;
exports[`loading templates can load a few templates from a xml string 1`] = `
"function anonymous(context,extra
) {
let h = this.utils.h;
let c1 = [], p1 = {key:1};
let vn1 = h('ul', p1, c1);
let c2 = [], p2 = {key:2};
let vn2 = h('li', p2, c2);
c1.push(vn2);
c2.push({text: \`ok\`});
let c3 = [], p3 = {key:3};
let vn3 = h('li', p3, c3);
c1.push(vn3);
c3.push({text: \`foo\`});
return vn1;
}"
`;
exports[`misc global 1`] = `
"function anonymous(context,extra
) {
context = Object.create(context);
let h = this.utils.h;
let c1 = [], p1 = {key:1};
let vn1 = h('div', p1, c1);
let _2 = [4,5,6];
if (!_2) { throw new Error('QWeb error: Invalid loop expression')}
if (typeof _2 === 'number') { _2 = Array.from(Array(_2).keys())}
let _3 = _2 instanceof Array ? _2 : Object.keys(_2);
let _4 = _2 instanceof Array ? _2 : Object.values(_2);
for (let i = 0; i < _3.length; i++) {
context.value_first = i === 0;
context.value_last = i === _3.length - 1;
context.value_parity = i % 2 === 0 ? 'even' : 'odd';
context.value_index = i;
context.value = _3[i];
context.value_value = _4[i];
let c5 = [], p5 = {key:5,on:{}};
let vn5 = h('span', p5, c5);
c1.push(vn5);
let e6 = context['value'];
if (e6 || e6 === 0) {
c5.push({text: e6});
}
let _7 = 'agüero';
let c8 = [], p8 = {key:8,attrs:{\\"falló\\": _7},on:{}};
let vn8 = h('Año', p8, c8);
c1.push(vn8);
let c9 = [], p9 = {key:9,on:{}};
let vn9 = h('span', p9, c9);
c8.push(vn9);
let e10 = 'aaa';
if (e10 || e10 === 0) {
c9.push({text: e10});
} else {
c9.push({text: \`foo default\`});
}
let c11 = [], p11 = {key:11,on:{}};
let vn11 = h('span', p11, c11);
c8.push(vn11);
let e12 = context['foo'];
if (e12 || e12 === 0) {
c11.push({text: e12});
} else {
c11.push({text: \`foo default\`});
}
let c13 = [], p13 = {key:13,on:{}};
let vn13 = h('span', p13, c13);
c8.push(vn13);
let e14 = 'bbb';
if (e14 || e14 === 0) {
c13.push({text: e14});
} else {
c13.push({text: \`foo default\`});
}
}
let c15 = [], p15 = {key:15,on:{}};
let vn15 = h('div', p15, c15);
c1.push(vn15);
let e16 = context['toto'];
if (e16 || e16 === 0) {
let frag17 = this.utils.getFragment(e16)
let p18 = {hook: {
insert: n => n.elm.parentNode.replaceChild(frag17, n.elm),
}};
let vn18 = h('div', p18)
c15.push(vn18);
} else {
c15.push({text: \`toto default\`});
}
return vn1;
}"
`;
exports[`special cases for some boolean html attributes/properties input type= checkbox, with t-att-checked 1`] = `
"function anonymous(context,extra
) {
let h = this.utils.h;
let _1 = 'checkbox';
let _2 = context['flag'];
let c3 = [], p3 = {key:3,attrs:{type: _1,checked: _2},props:{checked: _2}};
let vn3 = h('input', p3, c3);
return vn3;
}"
`;
exports[`special cases for some boolean html attributes/properties various boolean html attributes 1`] = `
"function anonymous(context,extra
) {
let h = this.utils.h;
let c1 = [], p1 = {key:1};
let vn1 = h('div', p1, c1);
let _2 = 'checkbox';
let _3 = 'checked';
let c4 = [], p4 = {key:4,attrs:{type: _2,checked: _3},props:{checked: _3}};
let vn4 = h('input', p4, c4);
c1.push(vn4);
let _5 = 'checked';
let c6 = [], p6 = {key:6,attrs:{checked: _5}};
let vn6 = h('input', p6, c6);
c1.push(vn6);
let _7 = 'checked';
let c8 = [], p8 = {key:8,attrs:{checked: _7}};
let vn8 = h('div', p8, c8);
c1.push(vn8);
let _9 = 'selected';
let c10 = [], p10 = {key:10,attrs:{selected: _9}};
let vn10 = h('div', p10, c10);
c1.push(vn10);
let _11 = 'selected';
let _12 = '1';
let c13 = [], p13 = {key:13,attrs:{selected: _11,other: _12},props:{selected: _11}};
let vn13 = h('option', p13, c13);
c1.push(vn13);
let _14 = 'readonly';
let c15 = [], p15 = {key:15,attrs:{readonly: _14},props:{readonly: _14}};
let vn15 = h('input', p15, c15);
c1.push(vn15);
let _16 = 'disabled';
let c17 = [], p17 = {key:17,attrs:{disabled: _16},props:{disabled: _16}};
let vn17 = h('button', p17, c17);
c1.push(vn17);
return vn1;
}"
`;
exports[`static templates div with a span child node 1`] = `
"function anonymous(context,extra
) {
let h = this.utils.h;
let c1 = [], p1 = {key:1};
let vn1 = h('div', p1, c1);
let c2 = [], p2 = {key:2};
let vn2 = h('span', p2, c2);
c1.push(vn2);
c2.push({text: \`word\`});
return vn1;
}"
`;
exports[`static templates div with a text node 1`] = `
"function anonymous(context,extra
) {
let h = this.utils.h;
let c1 = [], p1 = {key:1};
let vn1 = h('div', p1, c1);
c1.push({text: \`word\`});
return vn1;
}"
`;
exports[`static templates empty div 1`] = `
"function anonymous(context,extra
) {
let h = this.utils.h;
let c1 = [], p1 = {key:1};
let vn1 = h('div', p1, c1);
return vn1;
}"
`;
exports[`static templates simple string 1`] = `
"function anonymous(context,extra
) {
let h = this.utils.h;
let vn1 = {text: \`hello vdom\`};
return vn1;
}"
`;
exports[`t-call (template calling basic caller 1`] = `
"function anonymous(context,extra
) {
let h = this.utils.h;
let c1 = [], p1 = {key:1};
let vn1 = h('div', p1, c1);
c1.push({text: \`ok\`});
return vn1;
}"
`;
exports[`t-call (template calling inherit context 1`] = `
"function anonymous(context,extra
) {
let h = this.utils.h;
let c1 = [], p1 = {key:1};
let vn1 = h('div', p1, c1);
let e2 = 1;
if (e2 || e2 === 0) {
c1.push({text: e2});
}
return vn1;
}"
`;
exports[`t-call (template calling scoped parameters 1`] = `
"function anonymous(context,extra
) {
let h = this.utils.h;
let c1 = [], p1 = {key:1};
let vn1 = h('div', p1, c1);
c1.push({text: \`ok\`});
let e2 = context['foo'];
if (e2 || e2 === 0) {
c1.push({text: e2});
}
return vn1;
}"
`;
exports[`t-call (template calling with unused body 1`] = `
"function anonymous(context,extra
) {
let h = this.utils.h;
let c1 = [], p1 = {key:1};
let vn1 = h('div', p1, c1);
c1.push({text: \`ok\`});
return vn1;
}"
`;
exports[`t-call (template calling with unused setbody 1`] = `
"function anonymous(context,extra
) {
let h = this.utils.h;
let c1 = [], p1 = {key:1};
let vn1 = h('div', p1, c1);
c1.push({text: \`ok\`});
return vn1;
}"
`;
exports[`t-call (template calling with used body 1`] = `
"function anonymous(context,extra
) {
let h = this.utils.h;
let c1 = [], p1 = {key:1};
let vn1 = h('h1', p1, c1);
c1.push({text: \`ok\`});
return vn1;
}"
`;
exports[`t-call (template calling with used set body 1`] = `
"function anonymous(context,extra
) {
let h = this.utils.h;
let c1 = [], p1 = {key:1};
let vn1 = h('span', p1, c1);
let e2 = 'ok';
if (e2 || e2 === 0) {
c1.push({text: e2});
}
return vn1;
}"
`;
exports[`t-esc escaping on a node 1`] = `
"function anonymous(context,extra
) {
let h = this.utils.h;
let c1 = [], p1 = {key:1,on:{}};
let vn1 = h('span', p1, c1);
let e2 = 'ok';
if (e2 || e2 === 0) {
c1.push({text: e2});
}
return vn1;
}"
`;
exports[`t-esc escaping on a node with a body 1`] = `
"function anonymous(context,extra
) {
let h = this.utils.h;
let c1 = [], p1 = {key:1,on:{}};
let vn1 = h('span', p1, c1);
let e2 = 'ok';
if (e2 || e2 === 0) {
c1.push({text: e2});
} else {
c1.push({text: \`nope\`});
}
return vn1;
}"
`;
exports[`t-esc escaping on a node with a body, as a default 1`] = `
"function anonymous(context,extra
) {
let h = this.utils.h;
let c1 = [], p1 = {key:1,on:{}};
let vn1 = h('span', p1, c1);
let e2 = context['var'];
if (e2 || e2 === 0) {
c1.push({text: e2});
} else {
c1.push({text: \`nope\`});
}
return vn1;
}"
`;
exports[`t-esc literal 1`] = `
"function anonymous(context,extra
) {
let h = this.utils.h;
let c1 = [], p1 = {key:1};
let vn1 = h('span', p1, c1);
let e2 = 'ok';
if (e2 || e2 === 0) {
c1.push({text: e2});
}
return vn1;
}"
`;
exports[`t-esc variable 1`] = `
"function anonymous(context,extra
) {
let h = this.utils.h;
let c1 = [], p1 = {key:1};
let vn1 = h('span', p1, c1);
let e2 = context['var'];
if (e2 || e2 === 0) {
c1.push({text: e2});
}
return vn1;
}"
`;
exports[`t-if boolean value condition elif 1`] = `
"function anonymous(context,extra
) {
let h = this.utils.h;
let c1 = [], p1 = {key:1};
let vn1 = h('div', p1, c1);
if (context['color'] == 'black') {
c1.push({text: \`black pearl\`});
}
else if (context['color'] == 'yellow') {
c1.push({text: \`yellow submarine\`});
}
else if (context['color'] == 'red') {
c1.push({text: \`red is dead\`});
}
else {
c1.push({text: \`beer\`});
}
return vn1;
}"
`;
exports[`t-if boolean value condition else 1`] = `
"function anonymous(context,extra
) {
let h = this.utils.h;
let c1 = [], p1 = {key:1};
let vn1 = h('div', p1, c1);
let c2 = [], p2 = {key:2};
let vn2 = h('span', p2, c2);
c1.push(vn2);
c2.push({text: \`begin\`});
if (context['condition']) {
c1.push({text: \`ok\`});
}
else {
c1.push({text: \`ok-else\`});
}
let c3 = [], p3 = {key:3};
let vn3 = h('span', p3, c3);
c1.push(vn3);
c3.push({text: \`end\`});
return vn1;
}"
`;
exports[`t-if boolean value condition false else 1`] = `
"function anonymous(context,extra
) {
let h = this.utils.h;
let c1 = [], p1 = {key:1};
let vn1 = h('div', p1, c1);
let c2 = [], p2 = {key:2};
let vn2 = h('span', p2, c2);
c1.push(vn2);
c2.push({text: \`begin\`});
if (context['condition']) {
c1.push({text: \`fail\`});
}
else {
c1.push({text: \`fail-else\`});
}
let c3 = [], p3 = {key:3};
let vn3 = h('span', p3, c3);
c1.push(vn3);
c3.push({text: \`end\`});
return vn1;
}"
`;
exports[`t-if boolean value condition missing 1`] = `
"function anonymous(context,extra
) {
let h = this.utils.h;
let c1 = [], p1 = {key:1};
let vn1 = h('span', p1, c1);
if (context['condition']) {
c1.push({text: \`fail\`});
}
return vn1;
}"
`;
exports[`t-if boolean value false condition 1`] = `
"function anonymous(context,extra
) {
let h = this.utils.h;
let c1 = [], p1 = {key:1};
let vn1 = h('div', p1, c1);
if (context['condition']) {
c1.push({text: \`ok\`});
}
return vn1;
}"
`;
exports[`t-if boolean value true condition 1`] = `
"function anonymous(context,extra
) {
let h = this.utils.h;
let c1 = [], p1 = {key:1};
let vn1 = h('div', p1, c1);
if (context['condition']) {
c1.push({text: \`ok\`});
}
return vn1;
}"
`;
exports[`t-if can use some boolean operators in expressions 1`] = `
"function anonymous(context,extra
) {
let h = this.utils.h;
let c1 = [], p1 = {key:1};
let vn1 = h('div', p1, c1);
if (context['cond1'] && context['cond2']) {
c1.push({text: \`and\`});
}
if (context['cond1'] && context['cond3']) {
c1.push({text: \`nope\`});
}
if (context['cond1'] || context['cond3']) {
c1.push({text: \`or\`});
}
if (context['cond3'] || context['cond4']) {
c1.push({text: \`nope\`});
}
if (context['m'] > 3) {
c1.push({text: \`mgt\`});
}
if (context['n'] > 3) {
c1.push({text: \`ngt\`});
}
if (context['m'] < 3) {
c1.push({text: \`mlt\`});
}
if (context['n'] < 3) {
c1.push({text: \`nlt\`});
}
return vn1;
}"
`;
exports[`t-on can bind event handler 1`] = `
"function anonymous(context,extra
) {
let owner = context;
let h = this.utils.h;
let c1 = [], p1 = {key:1,on:{}};
let vn1 = h('button', p1, c1);
extra.handlers['click' + 1] = extra.handlers['click' + 1] || context['add'].bind(owner);
p1.on['click'] = extra.handlers['click' + 1];
c1.push({text: \`Click\`});
return vn1;
}"
`;
exports[`t-on can bind handlers with arguments 1`] = `
"function anonymous(context,extra
) {
let owner = context;
let h = this.utils.h;
let c1 = [], p1 = {key:1,on:{}};
let vn1 = h('button', p1, c1);
p1.on['click'] = context['add'].bind(owner, 5);
c1.push({text: \`Click\`});
return vn1;
}"
`;
exports[`t-on can bind handlers with empty object (with non empty inner string 1`] = `
"function anonymous(context,extra
) {
let owner = context;
let h = this.utils.h;
let c1 = [], p1 = {key:1,on:{}};
let vn1 = h('button', p1, c1);
p1.on['click'] = context['doSomething'].bind(owner, {});
c1.push({text: \`Click\`});
return vn1;
}"
`;
exports[`t-on can bind handlers with empty object 1`] = `
"function anonymous(context,extra
) {
let owner = context;
let h = this.utils.h;
let c1 = [], p1 = {key:1,on:{}};
let vn1 = h('button', p1, c1);
p1.on['click'] = context['doSomething'].bind(owner, {});
c1.push({text: \`Click\`});
return vn1;
}"
`;
exports[`t-on can bind handlers with loop variable as argument 1`] = `
"function anonymous(context,extra
) {
let owner = context;
context = Object.create(context);
let h = this.utils.h;
let c1 = [], p1 = {key:1};
let vn1 = h('ul', p1, c1);
let _2 = ['someval'];
if (!_2) { throw new Error('QWeb error: Invalid loop expression')}
if (typeof _2 === 'number') { _2 = Array.from(Array(_2).keys())}
let _3 = _2 instanceof Array ? _2 : Object.keys(_2);
let _4 = _2 instanceof Array ? _2 : Object.values(_2);
for (let i = 0; i < _3.length; i++) {
context.action_first = i === 0;
context.action_last = i === _3.length - 1;
context.action_parity = i % 2 === 0 ? 'even' : 'odd';
context.action_index = i;
context.action = _3[i];
context.action_value = _4[i];
let c5 = [], p5 = {key:5};
let vn5 = h('li', p5, c5);
c1.push(vn5);
let c6 = [], p6 = {key:6,on:{}};
let vn6 = h('a', p6, c6);
c5.push(vn6);
p6.on['click'] = context['activate'].bind(owner, context['action']);
c6.push({text: \`link\`});
}
return vn1;
}"
`;
exports[`t-on can bind handlers with object arguments 1`] = `
"function anonymous(context,extra
) {
let owner = context;
let h = this.utils.h;
let c1 = [], p1 = {key:1,on:{}};
let vn1 = h('button', p1, c1);
p1.on['click'] = context['add'].bind(owner, {val: 5});
c1.push({text: \`Click\`});
return vn1;
}"
`;
exports[`t-on can bind two event handlers 1`] = `
"function anonymous(context,extra
) {
let owner = context;
let h = this.utils.h;
let c1 = [], p1 = {key:1,on:{}};
let vn1 = h('button', p1, c1);
extra.handlers['click' + 1] = extra.handlers['click' + 1] || context['handleClick'].bind(owner);
p1.on['click'] = extra.handlers['click' + 1];
extra.handlers['dblclick' + 1] = extra.handlers['dblclick' + 1] || context['handleDblClick'].bind(owner);
p1.on['dblclick'] = extra.handlers['dblclick' + 1];
c1.push({text: \`Click\`});
return vn1;
}"
`;
exports[`t-on handler is bound to proper owner 1`] = `
"function anonymous(context,extra
) {
let owner = context;
let h = this.utils.h;
let c1 = [], p1 = {key:1,on:{}};
let vn1 = h('button', p1, c1);
extra.handlers['click' + 1] = extra.handlers['click' + 1] || context['add'].bind(owner);
p1.on['click'] = extra.handlers['click' + 1];
c1.push({text: \`Click\`});
return vn1;
}"
`;
exports[`t-raw literal 1`] = `
"function anonymous(context,extra
) {
let h = this.utils.h;
let c1 = [], p1 = {key:1};
let vn1 = h('span', p1, c1);
let e2 = 'ok';
if (e2 || e2 === 0) {
let frag3 = this.utils.getFragment(e2)
let p4 = {hook: {
insert: n => n.elm.parentNode.replaceChild(frag3, n.elm),
}};
let vn4 = h('div', p4)
c1.push(vn4);
}
return vn1;
}"
`;
exports[`t-raw not escaping 1`] = `
"function anonymous(context,extra
) {
let h = this.utils.h;
let c1 = [], p1 = {key:1};
let vn1 = h('div', p1, c1);
let e2 = context['var'];
if (e2 || e2 === 0) {
let frag3 = this.utils.getFragment(e2)
let p4 = {hook: {
insert: n => n.elm.parentNode.replaceChild(frag3, n.elm),
}};
let vn4 = h('div', p4)
c1.push(vn4);
}
return vn1;
}"
`;
exports[`t-raw t-raw and another sibling node 1`] = `
"function anonymous(context,extra
) {
let h = this.utils.h;
let c1 = [], p1 = {key:1};
let vn1 = h('span', p1, c1);
let c2 = [], p2 = {key:2};
let vn2 = h('span', p2, c2);
c1.push(vn2);
c2.push({text: \`hello\`});
let e3 = context['var'];
if (e3 || e3 === 0) {
let frag4 = this.utils.getFragment(e3)
let p5 = {hook: {
insert: n => n.elm.parentNode.replaceChild(frag4, n.elm),
}};
let vn5 = h('div', p5)
c1.push(vn5);
}
return vn1;
}"
`;
exports[`t-raw variable 1`] = `
"function anonymous(context,extra
) {
let h = this.utils.h;
let c1 = [], p1 = {key:1};
let vn1 = h('span', p1, c1);
let e2 = context['var'];
if (e2 || e2 === 0) {
let frag3 = this.utils.getFragment(e2)
let p4 = {hook: {
insert: n => n.elm.parentNode.replaceChild(frag3, n.elm),
}};
let vn4 = h('div', p4)
c1.push(vn4);
}
return vn1;
}"
`;
exports[`t-ref can get a ref on a node 1`] = `
"function anonymous(context,extra
) {
let h = this.utils.h;
let c1 = [], p1 = {key:1};
let vn1 = h('div', p1, c1);
let c2 = [], p2 = {key:2};
let vn2 = h('span', p2, c2);
c1.push(vn2);
p2.hook = {
create: (_, n) => context.refs['myspan'] = n.elm,
};
return vn1;
}"
`;
exports[`t-set evaluate value expression 1`] = `
"function anonymous(context,extra
) {
let h = this.utils.h;
let c1 = [], p1 = {key:1};
let vn1 = h('div', p1, c1);
let e2 = 1 + 2;
if (e2 || e2 === 0) {
c1.push({text: e2});
}
return vn1;
}"
`;
exports[`t-set evaluate value expression, part 2 1`] = `
"function anonymous(context,extra
) {
let h = this.utils.h;
let c1 = [], p1 = {key:1};
let vn1 = h('div', p1, c1);
let e2 = context['somevariable'] + 2;
if (e2 || e2 === 0) {
c1.push({text: e2});
}
return vn1;
}"
`;
exports[`t-set set from attribute literal 1`] = `
"function anonymous(context,extra
) {
let h = this.utils.h;
let c1 = [], p1 = {key:1};
let vn1 = h('div', p1, c1);
let e2 = 'ok';
if (e2 || e2 === 0) {
c1.push({text: e2});
}
return vn1;
}"
`;
exports[`t-set set from attribute lookup 1`] = `
"function anonymous(context,extra
) {
let h = this.utils.h;
let c1 = [], p1 = {key:1};
let vn1 = h('div', p1, c1);
let e2 = context['value'];
if (e2 || e2 === 0) {
c1.push({text: e2});
}
return vn1;
}"
`;
exports[`t-set set from body literal 1`] = `
"function anonymous(context,extra
) {
let h = this.utils.h;
let vn1 = {text: \`ok\`};
return vn1;
}"
`;
exports[`t-set set from body lookup 1`] = `
"function anonymous(context,extra
) {
let h = this.utils.h;
let c1 = [], p1 = {key:1};
let vn1 = h('div', p1, c1);
let e2 = context['value'];
if (e2 || e2 === 0) {
c1.push({text: e2});
}
return vn1;
}"
`;
exports[`t-set set from empty body 1`] = `
"function anonymous(context,extra
) {
let h = this.utils.h;
let c1 = [], p1 = {key:1};
let vn1 = h('div', p1, c1);
return vn1;
}"
`;
exports[`t-set value priority 1`] = `
"function anonymous(context,extra
) {
let h = this.utils.h;
let c1 = [], p1 = {key:1};
let vn1 = h('div', p1, c1);
let e2 = 1;
if (e2 || e2 === 0) {
c1.push({text: e2});
}
return vn1;
}"
`;
exports[`whitespace handling consecutives whitespaces are condensed into a single space 1`] = `
"function anonymous(context,extra
) {
let h = this.utils.h;
let c1 = [], p1 = {key:1};
let vn1 = h('div', p1, c1);
c1.push({text: \` abc \`});
return vn1;
}"
`;
exports[`whitespace handling nothing is done in pre tags 1`] = `
"function anonymous(context,extra
) {
let h = this.utils.h;
let c1 = [], p1 = {key:1};
let vn1 = h('pre', p1, c1);
c1.push({text: \` \`});
return vn1;
}"
`;
exports[`whitespace handling nothing is done in pre tags 2`] = `
"function anonymous(context,extra
) {
let h = this.utils.h;
let c1 = [], p1 = {key:1};
let vn1 = h('pre', p1, c1);
c1.push({text: \`
some text
\`});
return vn1;
}"
`;
exports[`whitespace handling nothing is done in pre tags 3`] = `
"function anonymous(context,extra
) {
let h = this.utils.h;
let c1 = [], p1 = {key:1};
let vn1 = h('pre', p1, c1);
c1.push({text: \`
\`});
return vn1;
}"
`;
exports[`whitespace handling white space only text nodes are condensed into a single space 1`] = `
"function anonymous(context,extra
) {
let h = this.utils.h;
let c1 = [], p1 = {key:1};
let vn1 = h('div', p1, c1);
c1.push({text: \` \`});
return vn1;
}"
`;
exports[`whitespace handling whitespace only text nodes with newlines are removed 1`] = `
"function anonymous(context,extra
) {
let h = this.utils.h;
let c1 = [], p1 = {key:1};
let vn1 = h('div', p1, c1);
let c2 = [], p2 = {key:2};
let vn2 = h('span', p2, c2);
c1.push(vn2);
c2.push({text: \`abc\`});
return vn1;
}"
`;