[FIX] qweb: properly display falsy values

While it is not tested, nor documented, the reference QWeb
implementation display the `false` value as "false". So, we have to
adapt the Owl implementation to match that behaviour.

At the same time, this commit uses 'let' instead of 'var' in various places,
to make the compiled code more consistant.
This commit is contained in:
Géry Debongnie
2019-12-12 22:27:52 +01:00
committed by aab-odoo
parent 0931a4dc5b
commit 29a80d0b28
12 changed files with 924 additions and 857 deletions
@@ -8,9 +8,9 @@ exports[`t-slot directive can define and call slots 1`] = `
let QWeb = this.constructor;
let parent = context;
let scope = Object.create(context);
var h = this.h;
let h = this.h;
let c1 = [], p1 = {key:1};
var vn1 = h('div', p1, c1);
let vn1 = h('div', p1, c1);
// Component 'Dialog'
let w2 = '__3__' in parent.__owl__.cmap ? parent.__owl__.children[parent.__owl__.cmap['__3__']] : false;
let props2 = {};
@@ -43,18 +43,18 @@ exports[`t-slot directive can define and call slots 2`] = `
"function anonymous(context, extra
) {
// Template name: \\"Dialog\\"
var h = this.h;
let h = this.h;
let c6 = [], p6 = {key:6};
var vn6 = h('div', p6, c6);
let vn6 = h('div', p6, c6);
let c7 = [], p7 = {key:7};
var vn7 = h('div', p7, c7);
let vn7 = h('div', p7, c7);
c6.push(vn7);
const slot8 = this.constructor.slots[context.__owl__.slotId + '_' + 'header'];
if (slot8) {
slot8.call(this, context.__owl__.scope, Object.assign({}, extra, {parentNode: c7, parent: extra.parent || context}));
}
let c9 = [], p9 = {key:9};
var vn9 = h('div', p9, c9);
let vn9 = h('div', p9, c9);
c6.push(vn9);
const slot10 = this.constructor.slots[context.__owl__.slotId + '_' + 'footer'];
if (slot10) {
@@ -68,10 +68,10 @@ exports[`t-slot directive can define and call slots 3`] = `
"function anonymous(context, extra
) {
// Template name: \\"slot_header_template\\"
var h = this.h;
let h = this.h;
let c1 = extra.parentNode;
let c4 = [], p4 = {key:4};
var vn4 = h('span', p4, c4);
let vn4 = h('span', p4, c4);
c1.push(vn4);
c4.push({text: \`header\`});
}"
@@ -81,10 +81,10 @@ exports[`t-slot directive can define and call slots 4`] = `
"function anonymous(context, extra
) {
// Template name: \\"slot_footer_template\\"
var h = this.h;
let h = this.h;
let c1 = extra.parentNode;
let c5 = [], p5 = {key:5};
var vn5 = h('span', p5, c5);
let vn5 = h('span', p5, c5);
c1.push(vn5);
c5.push({text: \`footer\`});
}"
@@ -94,10 +94,10 @@ exports[`t-slot directive content is the default slot 1`] = `
"function anonymous(context, extra
) {
// Template name: \\"slot_default_template\\"
var h = this.h;
let h = this.h;
let c1 = extra.parentNode;
let c4 = [], p4 = {key:4};
var vn4 = h('span', p4, c4);
let vn4 = h('span', p4, c4);
c1.push(vn4);
c4.push({text: \`sts rocks\`});
}"
@@ -107,9 +107,9 @@ exports[`t-slot directive dafault slots can define a default content 1`] = `
"function anonymous(context, extra
) {
// Template name: \\"__template__1\\"
var h = this.h;
let h = this.h;
let c4 = [], p4 = {key:4};
var vn4 = h('span', p4, c4);
let vn4 = h('span', p4, c4);
const slot5 = this.constructor.slots[context.__owl__.slotId + '_' + 'default'];
if (slot5) {
slot5.call(this, context.__owl__.scope, Object.assign({}, extra, {parentNode: c4, parent: extra.parent || context}));
@@ -124,7 +124,7 @@ exports[`t-slot directive default slot work with text nodes 1`] = `
"function anonymous(context, extra
) {
// Template name: \\"slot_default_template\\"
var h = this.h;
let h = this.h;
let c1 = extra.parentNode;
c1.push({text: \`sts rocks\`});
}"
@@ -134,14 +134,14 @@ exports[`t-slot directive multiple roots are allowed in a default slot 1`] = `
"function anonymous(context, extra
) {
// Template name: \\"slot_default_template\\"
var h = this.h;
let h = this.h;
let c1 = extra.parentNode;
let c4 = [], p4 = {key:4};
var vn4 = h('span', p4, c4);
let vn4 = h('span', p4, c4);
c1.push(vn4);
c4.push({text: \`sts\`});
let c5 = [], p5 = {key:5};
var vn5 = h('span', p5, c5);
let vn5 = h('span', p5, c5);
c1.push(vn5);
c5.push({text: \`rocks\`});
}"
@@ -151,14 +151,14 @@ exports[`t-slot directive multiple roots are allowed in a named slot 1`] = `
"function anonymous(context, extra
) {
// Template name: \\"slot_content_template\\"
var h = this.h;
let h = this.h;
let c1 = extra.parentNode;
let c4 = [], p4 = {key:4};
var vn4 = h('span', p4, c4);
let vn4 = h('span', p4, c4);
c1.push(vn4);
c4.push({text: \`sts\`});
let c5 = [], p5 = {key:5};
var vn5 = h('span', p5, c5);
let vn5 = h('span', p5, c5);
c1.push(vn5);
c5.push({text: \`rocks\`});
}"
@@ -168,9 +168,9 @@ exports[`t-slot directive named slots can define a default content 1`] = `
"function anonymous(context, extra
) {
// Template name: \\"__template__1\\"
var h = this.h;
let h = this.h;
let c4 = [], p4 = {key:4};
var vn4 = h('span', p4, c4);
let vn4 = h('span', p4, c4);
const slot5 = this.constructor.slots[context.__owl__.slotId + '_' + 'header'];
if (slot5) {
slot5.call(this, context.__owl__.scope, Object.assign({}, extra, {parentNode: c4, parent: extra.parent || context}));
@@ -187,10 +187,10 @@ exports[`t-slot directive refs are properly bound in slots 1`] = `
// Template name: \\"slot_footer_template\\"
let utils = this.constructor.utils;
context.__owl__.refs = context.__owl__.refs || {};
var h = this.h;
let h = this.h;
let c1 = extra.parentNode;
let c8 = [], p8 = {key:8,on:{}};
var vn8 = h('button', p8, c8);
let vn8 = h('button', p8, c8);
c1.push(vn8);
extra.handlers['click__9__'] = extra.handlers['click__9__'] || function (e) {if (!context.__owl__.isMounted){return}utils.getComponent(context)['doSomething'](e);};
p8.on['click'] = extra.handlers['click__9__'];
@@ -212,10 +212,10 @@ exports[`t-slot directive slots are rendered with proper context 1`] = `
) {
// Template name: \\"slot_footer_template\\"
let utils = this.constructor.utils;
var h = this.h;
let h = this.h;
let c1 = extra.parentNode;
let c8 = [], p8 = {key:8,on:{}};
var vn8 = h('button', p8, c8);
let vn8 = h('button', p8, c8);
c1.push(vn8);
extra.handlers['click__9__'] = extra.handlers['click__9__'] || function (e) {if (!context.__owl__.isMounted){return}utils.getComponent(context)['doSomething'](e);};
p8.on['click'] = extra.handlers['click__9__'];
@@ -228,10 +228,10 @@ exports[`t-slot directive slots are rendered with proper context, part 2 1`] = `
) {
// Template name: \\"Link\\"
let scope = Object.create(context);
var h = this.h;
var _12 = scope['props'].to;
let h = this.h;
let _12 = scope['props'].to;
let c13 = [], p13 = {key:13,attrs:{href: _12}};
var vn13 = h('a', p13, c13);
let vn13 = h('a', p13, c13);
const slot14 = this.constructor.slots[context.__owl__.slotId + '_' + 'default'];
if (slot14) {
slot14.call(this, context.__owl__.scope, Object.assign({}, extra, {parentNode: c13, parent: extra.parent || context}));
@@ -248,21 +248,21 @@ exports[`t-slot directive slots are rendered with proper context, part 2 2`] = `
let QWeb = this.constructor;
let parent = context;
let scope = Object.create(context);
var h = this.h;
let h = this.h;
let c1 = [], p1 = {key:1};
var vn1 = h('div', p1, c1);
let vn1 = h('div', p1, c1);
let c2 = [], p2 = {key:2};
var vn2 = h('u', p2, c2);
let vn2 = h('u', p2, c2);
c1.push(vn2);
var _3 = scope['state'].users;
let _3 = scope['state'].users;
if (!_3) { throw new Error('QWeb error: Invalid loop expression')}
var _4 = _5 = _3;
let _4 = _5 = _3;
if (!(_3 instanceof Array)) {
_4 = Object.keys(_3);
_5 = Object.values(_3);
}
var _length4 = _4.length;
const _origScope6 = scope;
let _length4 = _4.length;
let _origScope6 = scope;
scope = Object.assign(Object.create(context), scope);
for (let i1 = 0; i1 < _length4; i1++) {
scope.user_first = i1 === 0
@@ -272,7 +272,7 @@ exports[`t-slot directive slots are rendered with proper context, part 2 2`] = `
scope.user_value = _5[i1]
const nodeKey7 = scope['user'].id;
let c8 = [], p8 = {key:nodeKey7};
var vn8 = h('li', p8, c8);
let vn8 = h('li', p8, c8);
c2.push(vn8);
// Component 'Link'
let k10 = \`__10__\` + nodeKey7;
@@ -310,11 +310,11 @@ exports[`t-slot directive slots are rendered with proper context, part 2 3`] = `
) {
// Template name: \\"slot_default_template\\"
let scope = Object.create(context);
var h = this.h;
let h = this.h;
let c8 = extra.parentNode;
c8.push({text: \`User \`});
var _11 = scope['user'].name;
if (_11 || _11 === 0) {
let _11 = scope['user'].name;
if (_11 != null) {
c8.push({text: _11});
}
}"
@@ -325,10 +325,10 @@ exports[`t-slot directive slots are rendered with proper context, part 3 1`] = `
) {
// Template name: \\"Link\\"
let scope = Object.create(context);
var h = this.h;
var _11 = scope['props'].to;
let h = this.h;
let _11 = scope['props'].to;
let c12 = [], p12 = {key:12,attrs:{href: _11}};
var vn12 = h('a', p12, c12);
let vn12 = h('a', p12, c12);
const slot13 = this.constructor.slots[context.__owl__.slotId + '_' + 'default'];
if (slot13) {
slot13.call(this, context.__owl__.scope, Object.assign({}, extra, {parentNode: c12, parent: extra.parent || context}));
@@ -345,21 +345,21 @@ exports[`t-slot directive slots are rendered with proper context, part 3 2`] = `
let QWeb = this.constructor;
let parent = context;
let scope = Object.create(context);
var h = this.h;
let h = this.h;
let c1 = [], p1 = {key:1};
var vn1 = h('div', p1, c1);
let vn1 = h('div', p1, c1);
let c2 = [], p2 = {key:2};
var vn2 = h('u', p2, c2);
let vn2 = h('u', p2, c2);
c1.push(vn2);
var _3 = scope['state'].users;
let _3 = scope['state'].users;
if (!_3) { throw new Error('QWeb error: Invalid loop expression')}
var _4 = _5 = _3;
let _4 = _5 = _3;
if (!(_3 instanceof Array)) {
_4 = Object.keys(_3);
_5 = Object.values(_3);
}
var _length4 = _4.length;
const _origScope6 = scope;
let _length4 = _4.length;
let _origScope6 = scope;
scope = Object.assign(Object.create(context), scope);
for (let i1 = 0; i1 < _length4; i1++) {
scope.user_first = i1 === 0
@@ -369,7 +369,7 @@ exports[`t-slot directive slots are rendered with proper context, part 3 2`] = `
scope.user_value = _5[i1]
const nodeKey7 = scope['user'].id;
let c8 = [], p8 = {key:nodeKey7};
var vn8 = h('li', p8, c8);
let vn8 = h('li', p8, c8);
c2.push(vn8);
scope.userdescr = 'User '+scope['user'].name;
// Component 'Link'
@@ -408,9 +408,9 @@ exports[`t-slot directive slots are rendered with proper context, part 3 3`] = `
) {
// Template name: \\"slot_default_template\\"
let scope = Object.create(context);
var h = this.h;
let h = this.h;
let c8 = extra.parentNode;
if (scope.userdescr || scope.userdescr === 0) {
if (scope.userdescr != null) {
c8.push({text: scope.userdescr});
}
}"
@@ -424,9 +424,9 @@ exports[`t-slot directive slots are rendered with proper context, part 4 1`] = `
let QWeb = this.constructor;
let parent = context;
let scope = Object.create(context);
var h = this.h;
let h = this.h;
let c1 = [], p1 = {key:1};
var vn1 = h('div', p1, c1);
let vn1 = h('div', p1, c1);
scope.userdescr = 'User '+scope['state'].user.name;
// Component 'Link'
let w2 = '__3__' in parent.__owl__.cmap ? parent.__owl__.children[parent.__owl__.cmap['__3__']] : false;
@@ -461,9 +461,9 @@ exports[`t-slot directive slots are rendered with proper context, part 4 2`] = `
) {
// Template name: \\"slot_default_template\\"
let scope = Object.create(context);
var h = this.h;
let h = this.h;
let c1 = extra.parentNode;
if (scope.userdescr || scope.userdescr === 0) {
if (scope.userdescr != null) {
c1.push({text: scope.userdescr});
}
}"
@@ -475,7 +475,7 @@ exports[`t-slot directive template can just return a slot 1`] = `
// Template name: \\"__template__2\\"
let utils = this.constructor.utils;
let result;
var h = this.h;
let h = this.h;
const slot6 = this.constructor.slots[context.__owl__.slotId + '_' + 'default'];
if (slot6) {
let children7= []