[REF] qweb: use global nextID

and reset it to 1 before each test s.t. snapshots are deterministic.
This commit is contained in:
Aaron Bohy
2019-11-27 15:07:10 +01:00
parent 65344dbf1f
commit 12be815342
9 changed files with 178 additions and 180 deletions
@@ -241,11 +241,11 @@ exports[`class and style attributes with t-component t-att-class is properly add
let utils = this.constructor.utils;
let sibling = null;
var h = this.h;
let _2 = {'c':true};
Object.assign(_2, utils.toObj({d:context['state'].d}))
let c3 = [], p3 = {key:3,class:_2};
var vn3 = h('span', p3, c3);
return vn3;
let _9 = {'c':true};
Object.assign(_9, utils.toObj({d:context['state'].d}))
let c10 = [], p10 = {key:10,class:_9};
var vn10 = h('span', p10, c10);
return vn10;
}"
`;
@@ -302,11 +302,11 @@ exports[`class and style attributes with t-component t-att-class is properly add
let utils = this.constructor.utils;
let sibling = null;
var h = this.h;
let _2 = {'c':true};
Object.assign(_2, utils.toObj(context['state'].d?'d':''))
let c3 = [], p3 = {key:3,class:_2};
var vn3 = h('span', p3, c3);
return vn3;
let _9 = {'c':true};
Object.assign(_9, utils.toObj(context['state'].d?'d':''))
let c10 = [], p10 = {key:10,class:_9};
var vn10 = h('span', p10, c10);
return vn10;
}"
`;
@@ -1393,23 +1393,23 @@ exports[`t-slot directive can define and call slots 2`] = `
let owner = context;
let sibling = null;
var h = this.h;
let c1 = [], p1 = {key:1};
var vn1 = h('div', p1, c1);
let c2 = [], p2 = {key:2};
var vn2 = h('div', p2, c2);
c1.push(vn2);
const slot3 = this.constructor.slots[context.__owl__.slotId + '_' + 'header'];
if (slot3) {
slot3.call(this, context.__owl__.parent, Object.assign({}, extra, {parentNode: c2, vars: extra.vars, parent: owner}));
let c8 = [], p8 = {key:8};
var vn8 = h('div', p8, c8);
let c9 = [], p9 = {key:9};
var vn9 = h('div', p9, c9);
c8.push(vn9);
const slot10 = this.constructor.slots[context.__owl__.slotId + '_' + 'header'];
if (slot10) {
slot10.call(this, context.__owl__.parent, Object.assign({}, extra, {parentNode: c9, vars: extra.vars, parent: owner}));
}
let c4 = [], p4 = {key:4};
var vn4 = h('div', p4, c4);
c1.push(vn4);
const slot5 = this.constructor.slots[context.__owl__.slotId + '_' + 'footer'];
if (slot5) {
slot5.call(this, context.__owl__.parent, Object.assign({}, extra, {parentNode: c4, vars: extra.vars, parent: owner}));
let c11 = [], p11 = {key:11};
var vn11 = h('div', p11, c11);
c8.push(vn11);
const slot12 = this.constructor.slots[context.__owl__.slotId + '_' + 'footer'];
if (slot12) {
slot12.call(this, context.__owl__.parent, Object.assign({}, extra, {parentNode: c11, vars: extra.vars, parent: owner}));
}
return vn1;
return vn8;
}"
`;
@@ -1420,10 +1420,10 @@ exports[`t-slot directive can define and call slots 3`] = `
var h = this.h;
let c1 = extra.parentNode;
Object.assign(context, extra.fiber.scope);
let c7 = [], p7 = {key:7};
var vn7 = h('span', p7, c7);
c1.push(vn7);
c7.push({text: \`header\`});
let c6 = [], p6 = {key:6};
var vn6 = h('span', p6, c6);
c1.push(vn6);
c6.push({text: \`header\`});
}"
`;
@@ -1448,10 +1448,10 @@ exports[`t-slot directive content is the default slot 1`] = `
var h = this.h;
let c1 = extra.parentNode;
Object.assign(context, extra.fiber.scope);
let c7 = [], p7 = {key:7};
var vn7 = h('span', p7, c7);
c1.push(vn7);
c7.push({text: \`sts rocks\`});
let c6 = [], p6 = {key:6};
var vn6 = h('span', p6, c6);
c1.push(vn6);
c6.push({text: \`sts rocks\`});
}"
`;
@@ -1473,14 +1473,14 @@ exports[`t-slot directive multiple roots are allowed in a default slot 1`] = `
var h = this.h;
let c1 = extra.parentNode;
Object.assign(context, extra.fiber.scope);
let c6 = [], p6 = {key:6};
var vn6 = h('span', p6, c6);
c1.push(vn6);
c6.push({text: \`sts\`});
let c7 = [], p7 = {key:7};
var vn7 = h('span', p7, c7);
c1.push(vn7);
c7.push({text: \`sts\`});
let c8 = [], p8 = {key:8};
var vn8 = h('span', p8, c8);
c1.push(vn8);
c8.push({text: \`rocks\`});
c7.push({text: \`rocks\`});
}"
`;
@@ -1491,14 +1491,14 @@ exports[`t-slot directive multiple roots are allowed in a named slot 1`] = `
var h = this.h;
let c1 = extra.parentNode;
Object.assign(context, extra.fiber.scope);
let c6 = [], p6 = {key:6};
var vn6 = h('span', p6, c6);
c1.push(vn6);
c6.push({text: \`sts\`});
let c7 = [], p7 = {key:7};
var vn7 = h('span', p7, c7);
c1.push(vn7);
c7.push({text: \`sts\`});
let c8 = [], p8 = {key:8};
var vn8 = h('span', p8, c8);
c1.push(vn8);
c8.push({text: \`rocks\`});
c7.push({text: \`rocks\`});
}"
`;
@@ -1511,21 +1511,21 @@ exports[`t-slot directive refs are properly bound in slots 1`] = `
var h = this.h;
let c1 = extra.parentNode;
Object.assign(context, extra.fiber.scope);
let c11 = [], p11 = {key:11,on:{}};
var vn11 = h('button', p11, c11);
c1.push(vn11);
extra.handlers['click' + 11] = extra.handlers['click' + 11] || function (e) {const fn = context['doSomething'];if (fn) { fn.call(owner, e); } else { context.doSomething; }};
p11.on['click'] = extra.handlers['click' + 11];
const ref12 = \`myButton\`;
p11.hook = {
let c10 = [], p10 = {key:10,on:{}};
var vn10 = h('button', p10, c10);
c1.push(vn10);
extra.handlers['click' + 10] = extra.handlers['click' + 10] || function (e) {const fn = context['doSomething'];if (fn) { fn.call(owner, e); } else { context.doSomething; }};
p10.on['click'] = extra.handlers['click' + 10];
const ref11 = \`myButton\`;
p10.hook = {
create: (_, n) => {
context.__owl__.refs[ref12] = n.elm;
context.__owl__.refs[ref11] = n.elm;
},
destroy: () => {
delete context.__owl__.refs[ref12];
delete context.__owl__.refs[ref11];
},
};
c11.push({text: \`do something\`});
c10.push({text: \`do something\`});
}"
`;
@@ -1537,12 +1537,12 @@ exports[`t-slot directive slots are rendered with proper context 1`] = `
var h = this.h;
let c1 = extra.parentNode;
Object.assign(context, extra.fiber.scope);
let c11 = [], p11 = {key:11,on:{}};
var vn11 = h('button', p11, c11);
c1.push(vn11);
extra.handlers['click' + 11] = extra.handlers['click' + 11] || function (e) {const fn = context['doSomething'];if (fn) { fn.call(owner, e); } else { context.doSomething; }};
p11.on['click'] = extra.handlers['click' + 11];
c11.push({text: \`do something\`});
let c10 = [], p10 = {key:10,on:{}};
var vn10 = h('button', p10, c10);
c1.push(vn10);
extra.handlers['click' + 10] = extra.handlers['click' + 10] || function (e) {const fn = context['doSomething'];if (fn) { fn.call(owner, e); } else { context.doSomething; }};
p10.on['click'] = extra.handlers['click' + 10];
c10.push({text: \`do something\`});
}"
`;
@@ -1552,14 +1552,14 @@ exports[`t-slot directive slots are rendered with proper context, part 2 1`] = `
let owner = context;
let sibling = null;
var h = this.h;
var _1 = context['props'].to;
let c2 = [], p2 = {key:2,attrs:{href: _1}};
var vn2 = h('a', p2, c2);
const slot3 = this.constructor.slots[context.__owl__.slotId + '_' + 'default'];
if (slot3) {
slot3.call(this, context.__owl__.parent, Object.assign({}, extra, {parentNode: c2, vars: extra.vars, parent: owner}));
var _13 = context['props'].to;
let c14 = [], p14 = {key:14,attrs:{href: _13}};
var vn14 = h('a', p14, c14);
const slot15 = this.constructor.slots[context.__owl__.slotId + '_' + 'default'];
if (slot15) {
slot15.call(this, context.__owl__.parent, Object.assign({}, extra, {parentNode: c14, vars: extra.vars, parent: owner}));
}
return vn2;
return vn14;
}"
`;
@@ -1643,9 +1643,9 @@ exports[`t-slot directive slots are rendered with proper context, part 2 3`] = `
let c7 = extra.parentNode;
Object.assign(context, extra.fiber.scope);
c7.push({text: \`User \`});
var _13 = context['user'].name;
if (_13 || _13 === 0) {
c7.push({text: _13});
var _12 = context['user'].name;
if (_12 || _12 === 0) {
c7.push({text: _12});
}
}"
`;
@@ -1656,14 +1656,14 @@ exports[`t-slot directive slots are rendered with proper context, part 3 1`] = `
let owner = context;
let sibling = null;
var h = this.h;
var _1 = context['props'].to;
let c2 = [], p2 = {key:2,attrs:{href: _1}};
var vn2 = h('a', p2, c2);
const slot3 = this.constructor.slots[context.__owl__.slotId + '_' + 'default'];
if (slot3) {
slot3.call(this, context.__owl__.parent, Object.assign({}, extra, {parentNode: c2, vars: extra.vars, parent: owner}));
var _13 = context['props'].to;
let c14 = [], p14 = {key:14,attrs:{href: _13}};
var vn14 = h('a', p14, c14);
const slot15 = this.constructor.slots[context.__owl__.slotId + '_' + 'default'];
if (slot15) {
slot15.call(this, context.__owl__.parent, Object.assign({}, extra, {parentNode: c14, vars: extra.vars, parent: owner}));
}
return vn2;
return vn14;
}"
`;
@@ -1820,12 +1820,12 @@ exports[`t-slot directive template can just return a slot 1`] = `
let sibling = null;
let result;
var h = this.h;
const slot1 = this.constructor.slots[context.__owl__.slotId + '_' + 'default'];
if (slot1) {
let children2= []
const slot10 = this.constructor.slots[context.__owl__.slotId + '_' + 'default'];
if (slot10) {
let children11= []
result = {}
slot1.call(this, context.__owl__.parent, Object.assign({}, extra, {parentNode: children2, vars: extra.vars, parent: owner}));
utils.defineProxy(result, children2[0]);
slot10.call(this, context.__owl__.parent, Object.assign({}, extra, {parentNode: children11, vars: extra.vars, parent: owner}));
utils.defineProxy(result, children11[0]);
}
return result;
}"
+2
View File
@@ -1,6 +1,7 @@
import { Env } from "../src/component/component";
import { scheduler } from "../src/component/scheduler";
import { EvalContext, QWeb } from "../src/qweb/qweb";
import { CompilationContext } from "../src/qweb/compilation_context";
import { patch } from "../src/vdom";
import "../src/qweb/base_directives";
import "../src/qweb/extensions";
@@ -20,6 +21,7 @@ let TEMPLATES;
beforeEach(() => {
nextSlotId = QWeb.nextSlotId;
CompilationContext.nextID = 1;
slots = Object.assign({}, QWeb.slots);
nextId = QWeb.nextId;
TEMPLATES = Object.assign({}, QWeb.TEMPLATES);
+55 -55
View File
@@ -999,15 +999,15 @@ exports[`t-call (template calling recursive template, part 1 2`] = `
var h = this.h;
let c1 = extra.parentNode;
Object.assign(context, extra.fiber.scope);
let c4 = [], p4 = {key:4};
var vn4 = h('div', p4, c4);
c1.push(vn4);
let c5 = [], p5 = {key:5};
var vn5 = h('div', p5, c5);
c1.push(vn5);
let c6 = [], p6 = {key:6};
var vn6 = h('span', p6, c6);
c5.push(vn6);
c6.push({text: \`hey\`});
var vn5 = h('span', p5, c5);
c4.push(vn5);
c5.push({text: \`hey\`});
if (false) {
this.recursiveFns['__3'].call(this, context, Object.assign({}, extra, {parentNode: c5, fiber: {vars: {}, scope}}));
this.recursiveFns['__3'].call(this, context, Object.assign({}, extra, {parentNode: c4, fiber: {vars: {}, scope}}));
}
}"
`;
@@ -1071,36 +1071,36 @@ exports[`t-call (template calling recursive template, part 2 2`] = `
let c3 = extra.parentNode;
let _v0 = extra.fiber.vars._v0
Object.assign(context, extra.fiber.scope);
let c11 = [], p11 = {key:11};
var vn11 = h('div', p11, c11);
c3.push(vn11);
let c12 = [], p12 = {key:12};
var vn12 = h('div', p12, c12);
c3.push(vn12);
let c13 = [], p13 = {key:13};
var vn13 = h('p', p13, c13);
c12.push(vn13);
var _14 = _v0.val;
if (_14 || _14 === 0) {
c13.push({text: _14});
var vn12 = h('p', p12, c12);
c11.push(vn12);
var _13 = _v0.val;
if (_13 || _13 === 0) {
c12.push({text: _13});
}
var _15 = _v0.children||[];
if (!_15) { throw new Error('QWeb error: Invalid loop expression')}
var _16 = _17 = _15;
if (!(_15 instanceof Array)) {
_16 = Object.keys(_15);
_17 = Object.values(_15);
var _14 = _v0.children||[];
if (!_14) { throw new Error('QWeb error: Invalid loop expression')}
var _15 = _16 = _14;
if (!(_14 instanceof Array)) {
_15 = Object.keys(_14);
_16 = Object.values(_14);
}
var _length16 = _16.length;
for (let i1 = 0; i1 < _length16; i1++) {
var _length15 = _15.length;
for (let i1 = 0; i1 < _length15; i1++) {
context.subtree_first = i1 === 0;
scope.subtree_first = context.subtree_first;
context.subtree_last = i1 === _length16 - 1;
context.subtree_last = i1 === _length15 - 1;
scope.subtree_last = context.subtree_last;
context.subtree_index = i1;
scope.subtree_index = context.subtree_index;
context.subtree = _16[i1];
context.subtree = _15[i1];
scope.subtree = context.subtree;
context.subtree_value = _17[i1];
context.subtree_value = _16[i1];
scope.subtree_value = context.subtree_value;
this.recursiveFns['__10'].call(this, context, Object.assign({}, extra, {parentNode: c12, fiber: {vars: {_v0: context['subtree']}, scope}}));
this.recursiveFns['__10'].call(this, context, Object.assign({}, extra, {parentNode: c11, fiber: {vars: {_v0: context['subtree']}, scope}}));
}
}"
`;
@@ -1164,36 +1164,36 @@ exports[`t-call (template calling recursive template, part 3 2`] = `
let c3 = extra.parentNode;
let _v0 = extra.fiber.vars._v0
Object.assign(context, extra.fiber.scope);
let c11 = [], p11 = {key:11};
var vn11 = h('div', p11, c11);
c3.push(vn11);
let c12 = [], p12 = {key:12};
var vn12 = h('div', p12, c12);
c3.push(vn12);
let c13 = [], p13 = {key:13};
var vn13 = h('p', p13, c13);
c12.push(vn13);
var _14 = _v0.val;
if (_14 || _14 === 0) {
c13.push({text: _14});
var vn12 = h('p', p12, c12);
c11.push(vn12);
var _13 = _v0.val;
if (_13 || _13 === 0) {
c12.push({text: _13});
}
var _15 = _v0.children||[];
if (!_15) { throw new Error('QWeb error: Invalid loop expression')}
var _16 = _17 = _15;
if (!(_15 instanceof Array)) {
_16 = Object.keys(_15);
_17 = Object.values(_15);
var _14 = _v0.children||[];
if (!_14) { throw new Error('QWeb error: Invalid loop expression')}
var _15 = _16 = _14;
if (!(_14 instanceof Array)) {
_15 = Object.keys(_14);
_16 = Object.values(_14);
}
var _length16 = _16.length;
for (let i1 = 0; i1 < _length16; i1++) {
var _length15 = _15.length;
for (let i1 = 0; i1 < _length15; i1++) {
context.subtree_first = i1 === 0;
scope.subtree_first = context.subtree_first;
context.subtree_last = i1 === _length16 - 1;
context.subtree_last = i1 === _length15 - 1;
scope.subtree_last = context.subtree_last;
context.subtree_index = i1;
scope.subtree_index = context.subtree_index;
context.subtree = _16[i1];
context.subtree = _15[i1];
scope.subtree = context.subtree;
context.subtree_value = _17[i1];
context.subtree_value = _16[i1];
scope.subtree_value = context.subtree_value;
this.recursiveFns['__10'].call(this, context, Object.assign({}, extra, {parentNode: c12, fiber: {vars: {_v0: context['subtree']}, scope}}));
this.recursiveFns['__10'].call(this, context, Object.assign({}, extra, {parentNode: c11, fiber: {vars: {_v0: context['subtree']}, scope}}));
}
}"
`;
@@ -2595,12 +2595,12 @@ exports[`whitespace handling nothing is done in pre tags 2`] = `
) {
let sibling = null;
var h = this.h;
let c1 = [], p1 = {key:1};
var vn1 = h('pre', p1, c1);
c1.push({text: \`
let c2 = [], p2 = {key:2};
var vn2 = h('pre', p2, c2);
c2.push({text: \`
some text
\`});
return vn1;
return vn2;
}"
`;
@@ -2609,12 +2609,12 @@ exports[`whitespace handling nothing is done in pre tags 3`] = `
) {
let sibling = null;
var h = this.h;
let c1 = [], p1 = {key:1};
var vn1 = h('pre', p1, c1);
c1.push({text: \`
let c3 = [], p3 = {key:3};
var vn3 = h('pre', p3, c3);
c3.push({text: \`
\`});
return vn1;
return vn3;
}"
`;
+10 -10
View File
@@ -7,16 +7,16 @@ exports[`Link component can render simple cases 1`] = `
let owner = context;
let sibling = null;
var h = this.h;
let _1 = utils.toObj({'router-link-active':context['isActive']});
var _2 = context['href'];
let c3 = [], p3 = {key:3,attrs:{href: _2},class:_1,on:{}};
var vn3 = h('a', p3, c3);
extra.handlers['click' + 3] = extra.handlers['click' + 3] || function (e) {const fn = context['navigate'];if (fn) { fn.call(owner, e); } else { context.navigate; }};
p3.on['click'] = extra.handlers['click' + 3];
const slot4 = this.constructor.slots[context.__owl__.slotId + '_' + 'default'];
if (slot4) {
slot4.call(this, context.__owl__.parent, Object.assign({}, extra, {parentNode: c3, vars: extra.vars, parent: owner}));
let _6 = utils.toObj({'router-link-active':context['isActive']});
var _7 = context['href'];
let c8 = [], p8 = {key:8,attrs:{href: _7},class:_6,on:{}};
var vn8 = h('a', p8, c8);
extra.handlers['click' + 8] = extra.handlers['click' + 8] || function (e) {const fn = context['navigate'];if (fn) { fn.call(owner, e); } else { context.navigate; }};
p8.on['click'] = extra.handlers['click' + 8];
const slot9 = this.constructor.slots[context.__owl__.slotId + '_' + 'default'];
if (slot9) {
slot9.call(this, context.__owl__.parent, Object.assign({}, extra, {parentNode: c8, vars: extra.vars, parent: owner}));
}
return vn3;
return vn8;
}"
`;
@@ -11,36 +11,36 @@ exports[`RouteComponent can render simple cases 1`] = `
let result;
var h = this.h;
if (context['routeComponent']) {
const nodeKey1 = context['env'].router.currentRouteName;
const nodeKey6 = context['env'].router.currentRouteName;
//COMPONENT
let k4 = \`__5__\` + nodeKey1;
let w3 = k4 in parent.__owl__.cmap ? parent.__owl__.children[parent.__owl__.cmap[k4]] : false;
let vn6 = {};
result = vn6;
let props3 = Object.assign({}, context['env'].router.currentParams);
if (w3 && w3.__owl__.currentFiber && !w3.__owl__.vnode) {
w3.destroy();
w3 = false;
let k9 = \`__10__\` + nodeKey6;
let w8 = k9 in parent.__owl__.cmap ? parent.__owl__.children[parent.__owl__.cmap[k9]] : false;
let vn11 = {};
result = vn11;
let props8 = Object.assign({}, context['env'].router.currentParams);
if (w8 && w8.__owl__.currentFiber && !w8.__owl__.vnode) {
w8.destroy();
w8 = false;
}
if (w3) {
w3.__updateProps(props3, extra.fiber, undefined, undefined, sibling);
let pvnode = w3.__owl__.pvnode;
utils.defineProxy(vn6, pvnode);
if (w8) {
w8.__updateProps(props8, extra.fiber, undefined, undefined, sibling);
let pvnode = w8.__owl__.pvnode;
utils.defineProxy(vn11, pvnode);
} else {
let componentKey3 = \`routeComponent\`;
let W3 = context.constructor.components[componentKey3] || QWeb.components[componentKey3]|| context['routeComponent'];
if (!W3) {throw new Error('Cannot find the definition of component \\"' + componentKey3 + '\\"')}
w3 = new W3(parent, props3);
parent.__owl__.cmap[k4] = w3.__owl__.id;
let def2 = w3.__prepare(extra.fiber, undefined, undefined, sibling);
let pvnode = h('dummy', {key: k4, hook: {insert(vn) { let nvn=w3.__mount(fiber, pvnode.elm);pvnode.elm=nvn.elm;},remove() {},destroy(vn) {w3.destroy();}}});
const fiber = w3.__owl__.currentFiber;
def2.then(function () { if (fiber.isCompleted) { return; } const vnode = fiber.vnode; pvnode.sel = vnode.sel; });
utils.defineProxy(vn6, pvnode);
w3.__owl__.pvnode = pvnode;
let componentKey8 = \`routeComponent\`;
let W8 = context.constructor.components[componentKey8] || QWeb.components[componentKey8]|| context['routeComponent'];
if (!W8) {throw new Error('Cannot find the definition of component \\"' + componentKey8 + '\\"')}
w8 = new W8(parent, props8);
parent.__owl__.cmap[k9] = w8.__owl__.id;
let def7 = w8.__prepare(extra.fiber, undefined, undefined, sibling);
let pvnode = h('dummy', {key: k9, hook: {insert(vn) { let nvn=w8.__mount(fiber, pvnode.elm);pvnode.elm=nvn.elm;},remove() {},destroy(vn) {w8.destroy();}}});
const fiber = w8.__owl__.currentFiber;
def7.then(function () { if (fiber.isCompleted) { return; } const vnode = fiber.vnode; pvnode.sel = vnode.sel; });
utils.defineProxy(vn11, pvnode);
w8.__owl__.pvnode = pvnode;
}
w3.__owl__.parentLastFiberId = extra.fiber.id;
sibling = w3.__owl__.currentFiber || sibling;
w8.__owl__.parentLastFiberId = extra.fiber.id;
sibling = w8.__owl__.currentFiber || sibling;
}
return result;
}"