[IMP] qweb: turn handlers into function expressions only

For the sake of consistency with vanilla JS, and to allow some things
that were previously not possible.
This commit is contained in:
Samuel Degueldre
2021-11-12 12:56:07 +01:00
committed by Aaron Bohy
parent 756d32daa0
commit bca6afeb90
33 changed files with 280 additions and 227 deletions
@@ -9,7 +9,8 @@ exports[`t-on can bind event handler 1`] = `
let block1 = createBlock(\`<button block-handler-0=\\"click\\">Click</button>\`);
return function template(ctx, node, key = \\"\\") {
let d1 = [ctx, 'add'];
const v1 = ctx['add'];
let d1 = [v1, ctx];
return block1([d1]);
}
}"
@@ -24,8 +25,8 @@ exports[`t-on can bind handlers with arguments 1`] = `
let block1 = createBlock(\`<button block-handler-0=\\"click\\">Click</button>\`);
return function template(ctx, node, key = \\"\\") {
const arg1 = [5];
let d1 = [ctx, 'add', arg1];
const v1 = ctx['add'];
let d1 = [()=>v1(5), ctx];
return block1([d1]);
}
}"
@@ -40,8 +41,8 @@ exports[`t-on can bind handlers with empty object 1`] = `
let block1 = createBlock(\`<button block-handler-0=\\"click\\">Click</button>\`);
return function template(ctx, node, key = \\"\\") {
const arg1 = [{}];
let d1 = [ctx, 'doSomething', arg1];
const v1 = ctx['doSomething'];
let d1 = [()=>v1({}), ctx];
return block1([d1]);
}
}"
@@ -56,8 +57,8 @@ exports[`t-on can bind handlers with empty object (with non empty inner string)
let block1 = createBlock(\`<button block-handler-0=\\"click\\">Click</button>\`);
return function template(ctx, node, key = \\"\\") {
const arg1 = [{}];
let d1 = [ctx, 'doSomething', arg1];
const v1 = ctx['doSomething'];
let d1 = [()=>v1({}), ctx];
return block1([d1]);
}
}"
@@ -79,8 +80,9 @@ exports[`t-on can bind handlers with empty object (with non empty inner string)
ctx[\`action\`] = v_block2[i1];
ctx[\`action_index\`] = i1;
let key1 = ctx['action_index'];
const arg1 = [ctx['action']];
let d1 = [ctx, 'activate', arg1];
const v1 = ctx['activate'];
const v2 = ctx['action'];
let d1 = [()=>v1(v2), ctx];
c_block2[i1] = withKey(block3([d1]), key1);
}
let b2 = list(c_block2);
@@ -98,8 +100,8 @@ exports[`t-on can bind handlers with object arguments 1`] = `
let block1 = createBlock(\`<button block-handler-0=\\"click\\">Click</button>\`);
return function template(ctx, node, key = \\"\\") {
const arg1 = [{val:5}];
let d1 = [ctx, 'add', arg1];
const v1 = ctx['add'];
let d1 = [()=>v1({val:5}), ctx];
return block1([d1]);
}
}"
@@ -114,8 +116,10 @@ exports[`t-on can bind two event handlers 1`] = `
let block1 = createBlock(\`<button block-handler-0=\\"click\\" block-handler-1=\\"dblclick\\">Click</button>\`);
return function template(ctx, node, key = \\"\\") {
let d1 = [ctx, 'handleClick'];
let d2 = [ctx, 'handleDblClick'];
const v1 = ctx['handleClick'];
let d1 = [v1, ctx];
const v2 = ctx['handleDblClick'];
let d2 = [v2, ctx];
return block1([d1, d2]);
}
}"
@@ -130,7 +134,8 @@ exports[`t-on handler is bound to proper owner 1`] = `
let block1 = createBlock(\`<button block-handler-0=\\"click\\">Click</button>\`);
return function template(ctx, node, key = \\"\\") {
let d1 = [ctx, 'add'];
const v1 = ctx['add'];
let d1 = [v1, ctx];
return block1([d1]);
}
}"
@@ -150,7 +155,8 @@ exports[`t-on handler is bound to proper owner, part 2 1`] = `
for (let i1 = 0; i1 < l_block1; i1++) {
ctx[\`value\`] = v_block1[i1];
let key1 = ctx['value'];
let d1 = [ctx, 'add'];
const v1 = ctx['add'];
let d1 = [v1, ctx];
c_block1[i1] = withKey(block2([d1]), key1);
}
return list(c_block1);
@@ -167,7 +173,8 @@ exports[`t-on handler is bound to proper owner, part 3 1`] = `
let block1 = createBlock(\`<button block-handler-0=\\"click\\">Click</button>\`);
return function template(ctx, node, key = \\"\\") {
let d1 = [ctx, 'add'];
const v1 = ctx['add'];
let d1 = [v1, ctx];
return block1([d1]);
}
}"
@@ -181,7 +188,7 @@ exports[`t-on handler is bound to proper owner, part 3 2`] = `
const callTemplate_2 = getTemplate(\`sub\`);
return function template(ctx, node, key = \\"\\") {
return callTemplate_2(ctx, node, key + \`__1\`);
return callTemplate_2.call(this, ctx, node, key + \`__1\`);
}
}"
`;
@@ -195,7 +202,8 @@ exports[`t-on handler is bound to proper owner, part 4 1`] = `
let block1 = createBlock(\`<button block-handler-0=\\"click\\">Click</button>\`);
return function template(ctx, node, key = \\"\\") {
let d1 = [ctx, 'add'];
const v1 = ctx['add'];
let d1 = [v1, ctx];
return block1([d1]);
}
}"
@@ -218,7 +226,7 @@ exports[`t-on handler is bound to proper owner, part 4 2`] = `
ctx[\`value_index\`] = i1;
ctx[\`value_value\`] = k_block1[i1];
let key1 = ctx['value'];
c_block1[i1] = withKey(callTemplate_2(ctx, node, key + \`__1__\${key1}\`), key1);
c_block1[i1] = withKey(callTemplate_2.call(this, ctx, node, key + \`__1__\${key1}\`), key1);
}
return list(c_block1);
}
@@ -234,7 +242,8 @@ exports[`t-on receive event in first argument 1`] = `
let block1 = createBlock(\`<button block-handler-0=\\"click\\">Click</button>\`);
return function template(ctx, node, key = \\"\\") {
let d1 = [ctx, 'add'];
const v1 = ctx['add'];
let d1 = [v1, ctx];
return block1([d1]);
}
}"
@@ -249,8 +258,10 @@ exports[`t-on t-on modifiers (native listener) basic support for native listener
let block1 = createBlock(\`<div class=\\"myClass\\" block-handler-0=\\"click\\"><button block-handler-1=\\"click\\">Button</button></div>\`);
return function template(ctx, node, key = \\"\\") {
let d1 = [ctx, 'divClicked'];
let d2 = [ctx, 'btnClicked'];
const v1 = ctx['divClicked'];
let d1 = [v1, ctx];
const v2 = ctx['btnClicked'];
let d2 = [v2, ctx];
return block1([d1, d2]);
}
}"
@@ -265,7 +276,8 @@ exports[`t-on t-on modifiers (native listener) t-on combined with t-esc 1`] = `
let block1 = createBlock(\`<div><button block-handler-0=\\"click\\"><block-text-1/></button></div>\`);
return function template(ctx, node, key = \\"\\") {
let d1 = [ctx, 'onClick'];
const v1 = ctx['onClick'];
let d1 = [v1, ctx];
let d2 = ctx['text'];
return block1([d1, d2]);
}
@@ -281,7 +293,8 @@ exports[`t-on t-on modifiers (native listener) t-on combined with t-raw 1`] = `
let block1 = createBlock(\`<div><button block-handler-0=\\"click\\"><block-child-0/></button></div>\`);
return function template(ctx, node, key = \\"\\") {
let d1 = [ctx, 'onClick'];
const v1 = ctx['onClick'];
let d1 = [v1, ctx];
let b2 = html(ctx['html']);
return block1([d1], [b2]);
}
@@ -297,8 +310,10 @@ exports[`t-on t-on modifiers (native listener) t-on with .capture modifier 1`] =
let block1 = createBlock(\`<div block-handler-0=\\"click.capture\\"><button block-handler-1=\\"click\\">Button</button></div>\`);
return function template(ctx, node, key = \\"\\") {
let d1 = [\\"capture\\", ctx, 'onCapture'];
let d2 = [ctx, 'doSomething'];
const v1 = ctx['onCapture'];
let d1 = [\\"capture\\", v1, ctx];
const v2 = ctx['doSomething'];
let d2 = [v2, ctx];
return block1([d1, d2]);
}
}"
@@ -313,7 +328,7 @@ exports[`t-on t-on modifiers (native listener) t-on with empty handler (only mod
let block1 = createBlock(\`<div><button block-handler-0=\\"click.prevent\\">Button</button></div>\`);
return function template(ctx, node, key = \\"\\") {
let d1 = [\\"prevent\\", (e) => {const res = (() => { return })(); if (typeof res === 'function') { res(e) }}];
let d1 = [\\"prevent\\", , ctx];
return block1([d1]);
}
}"
@@ -328,7 +343,8 @@ exports[`t-on t-on modifiers (native listener) t-on with prevent and self modifi
let block1 = createBlock(\`<div><button block-handler-0=\\"click.prevent.self\\"><span>Button</span></button></div>\`);
return function template(ctx, node, key = \\"\\") {
let d1 = [\\"prevent\\",\\"self\\", ctx, 'onClick'];
const v1 = ctx['onClick'];
let d1 = [\\"prevent\\",\\"self\\", v1, ctx];
return block1([d1]);
}
}"
@@ -343,9 +359,12 @@ exports[`t-on t-on modifiers (native listener) t-on with prevent and/or stop mod
let block1 = createBlock(\`<div><button block-handler-0=\\"click.prevent\\">Button 1</button><button block-handler-1=\\"click.stop\\">Button 2</button><button block-handler-2=\\"click.prevent.stop\\">Button 3</button></div>\`);
return function template(ctx, node, key = \\"\\") {
let d1 = [\\"prevent\\", ctx, 'onClickPrevented'];
let d2 = [\\"stop\\", ctx, 'onClickStopped'];
let d3 = [\\"prevent\\",\\"stop\\", ctx, 'onClickPreventedAndStopped'];
const v1 = ctx['onClickPrevented'];
let d1 = [\\"prevent\\", v1, ctx];
const v2 = ctx['onClickStopped'];
let d2 = [\\"stop\\", v2, ctx];
const v3 = ctx['onClickPreventedAndStopped'];
let d3 = [\\"prevent\\",\\"stop\\", v3, ctx];
return block1([d1, d2, d3]);
}
}"
@@ -366,8 +385,9 @@ exports[`t-on t-on modifiers (native listener) t-on with prevent modifier in t-f
for (let i1 = 0; i1 < l_block2; i1++) {
ctx[\`project\`] = v_block2[i1];
let key1 = ctx['project'];
const arg1 = [ctx['project'].id];
let d1 = [\\"prevent\\", ctx, 'onEdit', arg1];
const v1 = ctx['onEdit'];
const v2 = ctx['project'];
let d1 = [\\"prevent\\", ev=>v1(v2.id,ev), ctx];
let d2 = ctx['project'].name;
c_block2[i1] = withKey(block3([d1, d2]), key1);
}
@@ -386,7 +406,8 @@ exports[`t-on t-on modifiers (native listener) t-on with self and prevent modifi
let block1 = createBlock(\`<div><button block-handler-0=\\"click.self.prevent\\"><span>Button</span></button></div>\`);
return function template(ctx, node, key = \\"\\") {
let d1 = [\\"self\\",\\"prevent\\", ctx, 'onClick'];
const v1 = ctx['onClick'];
let d1 = [\\"self\\",\\"prevent\\", v1, ctx];
return block1([d1]);
}
}"
@@ -401,8 +422,10 @@ exports[`t-on t-on modifiers (native listener) t-on with self modifier 1`] = `
let block1 = createBlock(\`<div><button block-handler-0=\\"click\\"><span>Button</span></button><button block-handler-1=\\"click.self\\"><span>Button</span></button></div>\`);
return function template(ctx, node, key = \\"\\") {
let d1 = [ctx, 'onClick'];
let d2 = [\\"self\\", ctx, 'onClickSelf'];
const v1 = ctx['onClick'];
let d1 = [v1, ctx];
const v2 = ctx['onClickSelf'];
let d2 = [\\"self\\", v2, ctx];
return block1([d1, d2]);
}
}"
@@ -417,8 +440,10 @@ exports[`t-on t-on modifiers (synthetic listener) basic support for synthetic 1`
let block1 = createBlock(\`<div block-handler-0=\\"click.synthetic\\"><button block-handler-1=\\"click.synthetic\\">Button</button></div>\`);
return function template(ctx, node, key = \\"\\") {
let d1 = [\\"synthetic\\", ctx, 'divClicked'];
let d2 = [\\"synthetic\\", ctx, 'btnClicked'];
const v1 = ctx['divClicked'];
let d1 = [\\"synthetic\\", v1, ctx];
const v2 = ctx['btnClicked'];
let d2 = [\\"synthetic\\", v2, ctx];
return block1([d1, d2]);
}
}"
@@ -434,7 +459,7 @@ exports[`t-on t-on with inline statement (function call) 1`] = `
return function template(ctx, node, key = \\"\\") {
const v1 = ctx['state'];
let d1 = [(e) => {const res = (() => { return v1.incrementCounter(2) })(); if (typeof res === 'function') { res(e) }}];
let d1 = [()=>v1.incrementCounter(2), ctx];
return block1([d1]);
}
}"
@@ -450,7 +475,7 @@ exports[`t-on t-on with inline statement 1`] = `
return function template(ctx, node, key = \\"\\") {
const v1 = ctx['state'];
let d1 = [(e) => {const res = (() => { return v1.counter++ })(); if (typeof res === 'function') { res(e) }}];
let d1 = [()=>v1.counter++, ctx];
return block1([d1]);
}
}"
@@ -466,7 +491,7 @@ exports[`t-on t-on with inline statement, part 2 1`] = `
return function template(ctx, node, key = \\"\\") {
const v1 = ctx['state'];
let d1 = [(e) => {const res = (() => { return v1.flag=!v1.flag })(); if (typeof res === 'function') { res(e) }}];
let d1 = [()=>v1.flag=!v1.flag, ctx];
return block1([d1]);
}
}"
@@ -483,7 +508,7 @@ exports[`t-on t-on with inline statement, part 3 1`] = `
return function template(ctx, node, key = \\"\\") {
const v1 = ctx['state'];
const v2 = ctx['someFunction'];
let d1 = [(e) => {const res = (() => { return v1.n=v2(3) })(); if (typeof res === 'function') { res(e) }}];
let d1 = [()=>v1.n=v2(3), ctx];
return block1([d1]);
}
}"
@@ -498,7 +523,8 @@ exports[`t-on t-on with t-call 1`] = `
let block1 = createBlock(\`<p block-handler-0=\\"click\\">lucas</p>\`);
return function template(ctx, node, key = \\"\\") {
let d1 = [ctx, 'update'];
const v1 = ctx['update'];
let d1 = [v1, ctx];
return block1([d1]);
}
}"
@@ -514,7 +540,7 @@ exports[`t-on t-on with t-call 2`] = `
let block1 = createBlock(\`<div><block-child-0/></div>\`);
return function template(ctx, node, key = \\"\\") {
let b2 = callTemplate_2(ctx, node, key + \`__1\`);
let b2 = callTemplate_2.call(this, ctx, node, key + \`__1\`);
return block1([], [b2]);
}
}"
@@ -529,8 +555,8 @@ exports[`t-on t-on, with arguments and t-call 1`] = `
let block1 = createBlock(\`<p block-handler-0=\\"click\\">lucas</p>\`);
return function template(ctx, node, key = \\"\\") {
const arg1 = [ctx['value']];
let d1 = [ctx, 'update', arg1];
const v1 = ctx['value'];
let d1 = [()=>this.update(v1), ctx];
return block1([d1]);
}
}"
@@ -546,7 +572,7 @@ exports[`t-on t-on, with arguments and t-call 2`] = `
let block1 = createBlock(\`<div><block-child-0/></div>\`);
return function template(ctx, node, key = \\"\\") {
let b2 = callTemplate_2(ctx, node, key + \`__1\`);
let b2 = callTemplate_2.call(this, ctx, node, key + \`__1\`);
return block1([], [b2]);
}
}"
+32 -21
View File
@@ -158,20 +158,20 @@ exports[`misc global 4`] = `
ctx = Object.create(ctx);
ctx[isBoundary] = 1;
setContextValue(ctx, \\"foo\\", 'aaa');
let b6 = callTemplate_2(ctx, node, key + \`__1__\${key1}\`);
let b6 = callTemplate_2.call(this, ctx, node, key + \`__1__\${key1}\`);
ctx = ctx.__proto__;
let b7 = callTemplate_4(ctx, node, key + \`__3__\${key1}\`);
let b7 = callTemplate_4.call(this, ctx, node, key + \`__3__\${key1}\`);
setContextValue(ctx, \\"foo\\", 'bbb');
let b8 = callTemplate_6(ctx, node, key + \`__5__\${key1}\`);
let b8 = callTemplate_6.call(this, ctx, node, key + \`__5__\${key1}\`);
let b5 = multi([b6, b7, b8]);
ctx[zero] = b5;
let b9 = callTemplate_8(ctx, node, key + \`__7__\${key1}\`);
let b9 = callTemplate_8.call(this, ctx, node, key + \`__7__\${key1}\`);
ctx = ctx.__proto__;
c_block2[i1] = withKey(multi([b4, b9]), key1);
}
ctx = ctx.__proto__;
let b2 = list(c_block2);
let b10 = callTemplate_10(ctx, node, key + \`__9\`);
let b10 = callTemplate_10.call(this, ctx, node, key + \`__9\`);
return block1([], [b2, b10]);
}
}"
@@ -182,7 +182,7 @@ exports[`misc other complex template 1`] = `
) {
let { text, createBlock, list, multi, html, toggler, component } = bdom;
let { withDefault, getTemplate, prepareList, withKey, zero, call, callSlot, capture, isBoundary, shallowEqual, setContextValue, toNumber } = helpers;
const callTemplate_3 = getTemplate(\`LOAD_INFOS_TEMPLATE\`);
const callTemplate_14 = getTemplate(\`LOAD_INFOS_TEMPLATE\`);
let block1 = createBlock(\`<div><header><nav class=\\"navbar navbar-expand-md navbar-light bg-light\\"><a block-attribute-0=\\"href\\"><b style=\\"color:#777;\\"><block-text-1/></b></a><button type=\\"button\\" class=\\"navbar-toggler\\" data-toggle=\\"collapse\\" data-target=\\"#top_menu_collapse\\"><span class=\\"navbar-toggler-icon\\"/></button><div class=\\"collapse navbar-collapse\\" id=\\"top_menu_collapse\\" aria-expanded=\\"false\\"><ul class=\\"nav navbar-nav ml-auto text-right\\" id=\\"top_menu\\"><block-child-0/><li class=\\"nav-item divider\\"/><block-child-1/></ul><div><div class=\\"input-group input-group-sm\\"><div class=\\"input-group-prepend input-group-sm\\"><button class=\\"btn btn-default fa fa-cog\\" title=\\"Settings\\" block-handler-2=\\"click\\"/><button class=\\"btn btn-default\\" block-handler-3=\\"click\\"> More </button><block-child-2/></div><input class=\\"form-control\\" type=\\"text\\" placeholder=\\"Search\\" aria-label=\\"Search\\" name=\\"search\\" block-attribute-4=\\"value\\" block-handler-5=\\"keyup\\" block-handler-6=\\"change\\" block-ref=\\"7\\"/><div class=\\"input-group-append\\"><button class=\\"btn btn-default fa fa-eraser\\" block-handler-8=\\"click\\"/></div></div></div></div></nav></header><div class=\\"container-fluid\\" block-ref=\\"9\\"><div class=\\"row\\"><!--div class=\\"form-group col-md-6\\">
<h5>Search options</h5>
@@ -223,8 +223,9 @@ exports[`misc other complex template 1`] = `
for (let i1 = 0; i1 < l_block2; i1++) {
ctx[\`project\`] = v_block2[i1];
let key1 = ctx['project'].id;
const arg1 = [ctx['project']];
let d3 = [ctx, 'selectProject', arg1];
const v1 = ctx['selectProject'];
const v2 = ctx['project'];
let d3 = [v1(v2), ctx];
let d4 = ctx['project'].name;
c_block2[i1] = withKey(block3([d3, d4]), key1);
}
@@ -256,8 +257,10 @@ exports[`misc other complex template 1`] = `
}
b4 = multi([b5, b6]);
}
let d11 = [ctx, 'toggleSettingsMenu'];
let d12 = [ctx, 'toggleMore'];
const v3 = ctx['toggleSettingsMenu'];
let d11 = [v3, ctx];
const v4 = ctx['toggleMore'];
let d12 = [v4, ctx];
if (ctx['categories']&&ctx['categories'].length>1) {
ctx = Object.create(ctx);
const [k_block15, v_block15, l_block15, c_block15] = prepareList(ctx['categories']);
@@ -274,10 +277,13 @@ exports[`misc other complex template 1`] = `
b14 = block14([], [b15]);
}
let d16 = ctx['search'].value;
let d17 = [ctx, 'updateFilter'];
let d18 = [ctx, 'updateFilter'];
const v5 = ctx['updateFilter'];
let d17 = [v5, ctx];
const v6 = ctx['updateFilter'];
let d18 = [v6, ctx];
let d19 = (el) => refs[\`search_input\`] = el;
let d20 = [ctx, 'clearSearch'];
const v7 = ctx['clearSearch'];
let d20 = [v7, ctx];
let d21 = (el) => refs[\`settings_menu\`] = el;
if (ctx['triggers']) {
ctx = Object.create(ctx);
@@ -291,7 +297,8 @@ exports[`misc other complex template 1`] = `
let d23 = \`trigger_\${ctx['trigger'].id}\`;
let d24 = ctx['options'].trigger_display[ctx['trigger'].id];
let d25 = ctx['trigger'].id;
let d26 = [ctx, 'updateTriggerDisplay'];
const v8 = ctx['updateTriggerDisplay'];
let d26 = [v8, ctx];
let d27 = \`trigger_\${ctx['trigger'].id}\`;
let d28 = ctx['trigger'].name;
b20 = block20([d22, d23, d24, d25, d26, d27, d28]);
@@ -300,15 +307,19 @@ exports[`misc other complex template 1`] = `
}
ctx = ctx.__proto__;
let b18 = list(c_block18);
let d29 = [ctx, 'triggerAll'];
let d30 = [ctx, 'triggerNone'];
let d31 = [ctx, 'triggerDefault'];
let d32 = [ctx, 'toggleSettingsMenu'];
const v9 = ctx['triggerAll'];
let d29 = [v9, ctx];
const v10 = ctx['triggerNone'];
let d30 = [v10, ctx];
const v11 = ctx['triggerDefault'];
let d31 = [v11, ctx];
const v12 = ctx['toggleSettingsMenu'];
let d32 = [v12, ctx];
let b21 = block21([d29, d30, d31, d32]);
b17 = multi([b18, b21]);
}
if (ctx['load_infos']) {
b22 = callTemplate_3(ctx, node, key + \`__2\`);
b22 = callTemplate_14.call(this, ctx, node, key + \`__13\`);
}
if (ctx['message']) {
let d33 = ctx['message'];
@@ -317,8 +328,8 @@ exports[`misc other complex template 1`] = `
if (!ctx['project']) {
b24 = block24();
} else {
let b26 = component(\`BundlesList\`, {bundles: ctx['bundles'].sticky,category_custom_views: ctx['category_custom_views'],search: ctx['search']}, key + \`__4\`, node, ctx);
let b27 = component(\`BundlesList\`, {bundles: ctx['bundles'].dev,search: ctx['search']}, key + \`__5\`, node, ctx);
let b26 = component(\`BundlesList\`, {bundles: ctx['bundles'].sticky,category_custom_views: ctx['category_custom_views'],search: ctx['search']}, key + \`__15\`, node, ctx);
let b27 = component(\`BundlesList\`, {bundles: ctx['bundles'].dev,search: ctx['search']}, key + \`__16\`, node, ctx);
b25 = block25([], [b26, b27]);
}
return block1([d1, d2, d11, d12, d16, d17, d18, d19, d20, d21], [b2, b4, b14, b17, b22, b23, b24, b25]);
+33 -33
View File
@@ -24,7 +24,7 @@ exports[`t-call (template calling) basic caller 2`] = `
let block1 = createBlock(\`<div><block-child-0/></div>\`);
return function template(ctx, node, key = \\"\\") {
let b2 = callTemplate_2(ctx, node, key + \`__1\`);
let b2 = callTemplate_2.call(this, ctx, node, key + \`__1\`);
return block1([], [b2]);
}
}"
@@ -52,7 +52,7 @@ exports[`t-call (template calling) basic caller, no parent node 2`] = `
const callTemplate_2 = getTemplate(\`_basic-callee\`);
return function template(ctx, node, key = \\"\\") {
return callTemplate_2(ctx, node, key + \`__1\`);
return callTemplate_2.call(this, ctx, node, key + \`__1\`);
}
}"
`;
@@ -91,7 +91,7 @@ exports[`t-call (template calling) call with several sub nodes on same line 2`]
let b5 = block5();
let b2 = multi([b3, b4, b5]);
ctx[zero] = b2;
let b6 = callTemplate_2(ctx, node, key + \`__1\`);
let b6 = callTemplate_2.call(this, ctx, node, key + \`__1\`);
return block1([], [b6]);
}
}"
@@ -129,7 +129,7 @@ exports[`t-call (template calling) cascading t-call t-raw='0' 2`] = `
let b4 = html(ctx[zero]);
let b2 = multi([b3, b4]);
ctx[zero] = b2;
let b5 = callTemplate_2(ctx, node, key + \`__1\`);
let b5 = callTemplate_2.call(this, ctx, node, key + \`__1\`);
return block1([], [b5]);
}
}"
@@ -152,7 +152,7 @@ exports[`t-call (template calling) cascading t-call t-raw='0' 3`] = `
let b4 = html(ctx[zero]);
let b2 = multi([b3, b4]);
ctx[zero] = b2;
let b5 = callTemplate_2(ctx, node, key + \`__1\`);
let b5 = callTemplate_2.call(this, ctx, node, key + \`__1\`);
return block1([], [b5]);
}
}"
@@ -177,7 +177,7 @@ exports[`t-call (template calling) cascading t-call t-raw='0' 4`] = `
let b5 = block5();
let b2 = multi([b3, b4, b5]);
ctx[zero] = b2;
let b6 = callTemplate_2(ctx, node, key + \`__1\`);
let b6 = callTemplate_2.call(this, ctx, node, key + \`__1\`);
return block1([], [b6]);
}
}"
@@ -215,7 +215,7 @@ exports[`t-call (template calling) cascading t-call t-raw='0', without external
let b3 = html(ctx[zero]);
let b1 = multi([b2, b3]);
ctx[zero] = b1;
return callTemplate_2(ctx, node, key + \`__1\`);
return callTemplate_2.call(this, ctx, node, key + \`__1\`);
}
}"
`;
@@ -236,7 +236,7 @@ exports[`t-call (template calling) cascading t-call t-raw='0', without external
let b3 = html(ctx[zero]);
let b1 = multi([b2, b3]);
ctx[zero] = b1;
return callTemplate_2(ctx, node, key + \`__1\`);
return callTemplate_2.call(this, ctx, node, key + \`__1\`);
}
}"
`;
@@ -259,7 +259,7 @@ exports[`t-call (template calling) cascading t-call t-raw='0', without external
let b4 = block4();
let b1 = multi([b2, b3, b4]);
ctx[zero] = b1;
return callTemplate_2(ctx, node, key + \`__1\`);
return callTemplate_2.call(this, ctx, node, key + \`__1\`);
}
}"
`;
@@ -335,7 +335,7 @@ exports[`t-call (template calling) inherit context 2`] = `
ctx = Object.create(ctx);
ctx[isBoundary] = 1
setContextValue(ctx, \\"foo\\", 1);
let b2 = callTemplate_2(ctx, node, key + \`__1\`);
let b2 = callTemplate_2.call(this, ctx, node, key + \`__1\`);
return block1([], [b2]);
}
}"
@@ -353,7 +353,7 @@ exports[`t-call (template calling) recursive template, part 1 1`] = `
return function template(ctx, node, key = \\"\\") {
let b2;
if (false) {
b2 = callTemplate_2(ctx, node, key + \`__1\`);
b2 = callTemplate_2.call(this, ctx, node, key + \`__1\`);
}
return block1([], [b2]);
}
@@ -375,7 +375,7 @@ exports[`t-call (template calling) recursive template, part 2 1`] = `
ctx = Object.create(ctx);
ctx[isBoundary] = 1;
setContextValue(ctx, \\"node\\", ctx['root']);
let b2 = callTemplate_2(ctx, node, key + \`__1\`);
let b2 = callTemplate_2.call(this, ctx, node, key + \`__1\`);
return block1([], [b2]);
}
}"
@@ -406,7 +406,7 @@ exports[`t-call (template calling) recursive template, part 2 2`] = `
ctx = Object.create(ctx);
ctx[isBoundary] = 1;
setContextValue(ctx, \\"node\\", ctx['subtree']);
c_block2[i1] = withKey(callTemplate_2(ctx, node, key + \`__1__\${key1}\`), key1);
c_block2[i1] = withKey(callTemplate_2.call(this, ctx, node, key + \`__1__\${key1}\`), key1);
ctx = ctx.__proto__;
}
let b2 = list(c_block2);
@@ -430,7 +430,7 @@ exports[`t-call (template calling) recursive template, part 3 1`] = `
ctx = Object.create(ctx);
ctx[isBoundary] = 1;
setContextValue(ctx, \\"node\\", ctx['root']);
let b2 = callTemplate_2(ctx, node, key + \`__1\`);
let b2 = callTemplate_2.call(this, ctx, node, key + \`__1\`);
return block1([], [b2]);
}
}"
@@ -461,7 +461,7 @@ exports[`t-call (template calling) recursive template, part 3 2`] = `
ctx = Object.create(ctx);
ctx[isBoundary] = 1;
setContextValue(ctx, \\"node\\", ctx['subtree']);
c_block2[i1] = withKey(callTemplate_2(ctx, node, key + \`__1__\${key1}\`), key1);
c_block2[i1] = withKey(callTemplate_2.call(this, ctx, node, key + \`__1__\${key1}\`), key1);
ctx = ctx.__proto__;
}
let b2 = list(c_block2);
@@ -486,7 +486,7 @@ exports[`t-call (template calling) recursive template, part 4: with t-set recurs
ctx[isBoundary] = 1;
setContextValue(ctx, \\"recursive_idx\\", 1);
setContextValue(ctx, \\"node\\", ctx['root']);
let b2 = callTemplate_2(ctx, node, key + \`__1\`);
let b2 = callTemplate_2.call(this, ctx, node, key + \`__1\`);
return block1([], [b2]);
}
}"
@@ -519,7 +519,7 @@ exports[`t-call (template calling) recursive template, part 4: with t-set recurs
ctx = Object.create(ctx);
ctx[isBoundary] = 1;
setContextValue(ctx, \\"node\\", ctx['subtree']);
c_block2[i1] = withKey(callTemplate_2(ctx, node, key + \`__1__\${key1}\`), key1);
c_block2[i1] = withKey(callTemplate_2.call(this, ctx, node, key + \`__1__\${key1}\`), key1);
ctx = ctx.__proto__;
}
let b2 = list(c_block2);
@@ -555,7 +555,7 @@ exports[`t-call (template calling) scoped parameters 2`] = `
ctx = Object.create(ctx);
ctx[isBoundary] = 1;
setContextValue(ctx, \\"foo\\", 42);
let b2 = callTemplate_2(ctx, node, key + \`__1\`);
let b2 = callTemplate_2.call(this, ctx, node, key + \`__1\`);
ctx = ctx.__proto__;
let d1 = ctx['foo'];
return block1([d1], [b2]);
@@ -591,7 +591,7 @@ exports[`t-call (template calling) scoped parameters, part 2 2`] = `
ctx = Object.create(ctx);
ctx[isBoundary] = 1;
setContextValue(ctx, \\"foo\\", 42);
let b2 = callTemplate_2(ctx, node, key + \`__1\`);
let b2 = callTemplate_2.call(this, ctx, node, key + \`__1\`);
ctx = ctx.__proto__;
let d1 = ctx['foo'];
return block1([d1], [b2]);
@@ -609,7 +609,7 @@ exports[`t-call (template calling) t-call allowed on a non t node 1`] = `
let block1 = createBlock(\`<div><block-child-0/></div>\`);
return function template(ctx, node, key = \\"\\") {
let b2 = callTemplate_2(ctx, node, key + \`__1\`);
let b2 = callTemplate_2.call(this, ctx, node, key + \`__1\`);
return block1([], [b2]);
}
}"
@@ -658,7 +658,7 @@ exports[`t-call (template calling) t-call with body content as root of a templat
ctx[isBoundary] = 1;
let b1 = block1();
ctx[zero] = b1;
return callTemplate_2(ctx, node, key + \`__1\`);
return callTemplate_2.call(this, ctx, node, key + \`__1\`);
}
}"
`;
@@ -675,7 +675,7 @@ exports[`t-call (template calling) t-call with t-if 1`] = `
return function template(ctx, node, key = \\"\\") {
let b2;
if (ctx['flag']) {
b2 = callTemplate_2(ctx, node, key + \`__1\`);
b2 = callTemplate_2.call(this, ctx, node, key + \`__1\`);
}
return block1([], [b2]);
}
@@ -711,7 +711,7 @@ exports[`t-call (template calling) t-call with t-set inside and body text conten
ctx = Object.create(ctx);
ctx[isBoundary] = 1;
setContextValue(ctx, \\"val\\", \`yip yip\`);
let b2 = callTemplate_2(ctx, node, key + \`__1\`);
let b2 = callTemplate_2.call(this, ctx, node, key + \`__1\`);
return block1([], [b2]);
}
}"
@@ -757,7 +757,7 @@ exports[`t-call (template calling) t-call with t-set inside and outside 1`] = `
ctx = Object.create(ctx);
ctx[isBoundary] = 1;
setContextValue(ctx, \\"val3\\", ctx['val']*3);
c_block2[i1] = withKey(callTemplate_2(ctx, node, key + \`__1__\${key1}\`), key1);
c_block2[i1] = withKey(callTemplate_2.call(this, ctx, node, key + \`__1__\${key1}\`), key1);
ctx = ctx.__proto__;
}
let b2 = list(c_block2);
@@ -806,7 +806,7 @@ exports[`t-call (template calling) t-call with t-set inside and outside. 2 1`] =
ctx = Object.create(ctx);
ctx[isBoundary] = 1;
setContextValue(ctx, \\"val3\\", ctx['val']*3);
c_block2[i1] = withKey(callTemplate_2(ctx, node, key + \`__1__\${key1}\`), key1);
c_block2[i1] = withKey(callTemplate_2.call(this, ctx, node, key + \`__1__\${key1}\`), key1);
ctx = ctx.__proto__;
}
let b2 = list(c_block2);
@@ -845,7 +845,7 @@ exports[`t-call (template calling) t-call with t-set inside and outside. 2 3`] =
ctx = Object.create(ctx);
ctx[isBoundary] = 1
setContextValue(ctx, \\"w\\", 'fromwrapper');
let b2 = callTemplate_2(ctx, node, key + \`__1\`);
let b2 = callTemplate_2.call(this, ctx, node, key + \`__1\`);
return block1([], [b2]);
}
}"
@@ -896,12 +896,12 @@ exports[`t-call (template calling) t-call, conditional and t-set in t-call body
let b2,b3;
setContextValue(ctx, \\"v1\\", 'elif');
if (ctx['v1']==='if') {
b2 = callTemplate_2(ctx, node, key + \`__1\`);
b2 = callTemplate_2.call(this, ctx, node, key + \`__1\`);
} else if (ctx['v1']==='elif') {
ctx = Object.create(ctx);
ctx[isBoundary] = 1;
setContextValue(ctx, \\"v\\", 'success');
b3 = callTemplate_4(ctx, node, key + \`__3\`);
b3 = callTemplate_4.call(this, ctx, node, key + \`__3\`);
ctx = ctx.__proto__;
}
return block1([], [b2, b3]);
@@ -922,7 +922,7 @@ exports[`t-call (template calling) t-esc inside t-call, with t-set outside 1`] =
ctx = Object.create(ctx);
ctx[isBoundary] = 1
setContextValue(ctx, \\"v\\", \`Hi\`);
let b2 = callTemplate_2(ctx, node, key + \`__1\`);
let b2 = callTemplate_2.call(this, ctx, node, key + \`__1\`);
return block1([], [b2]);
}
}"
@@ -969,7 +969,7 @@ exports[`t-call (template calling) with unused body 2`] = `
ctx[isBoundary] = 1;
let b1 = text(\`WHEEE\`);
ctx[zero] = b1;
return callTemplate_2(ctx, node, key + \`__1\`);
return callTemplate_2.call(this, ctx, node, key + \`__1\`);
}
}"
`;
@@ -1001,7 +1001,7 @@ exports[`t-call (template calling) with unused setbody 2`] = `
ctx = Object.create(ctx);
ctx[isBoundary] = 1;
setContextValue(ctx, \\"qux\\", 3);
return callTemplate_2(ctx, node, key + \`__1\`);
return callTemplate_2.call(this, ctx, node, key + \`__1\`);
}
}"
`;
@@ -1033,7 +1033,7 @@ exports[`t-call (template calling) with used body 2`] = `
ctx[isBoundary] = 1;
let b1 = text(\`ok\`);
ctx[zero] = b1;
return callTemplate_2(ctx, node, key + \`__1\`);
return callTemplate_2.call(this, ctx, node, key + \`__1\`);
}
}"
`;
@@ -1065,7 +1065,7 @@ exports[`t-call (template calling) with used setbody 2`] = `
ctx = Object.create(ctx);
ctx[isBoundary] = 1;
setContextValue(ctx, \\"foo\\", 'ok');
let b2 = callTemplate_2(ctx, node, key + \`__1\`);
let b2 = callTemplate_2.call(this, ctx, node, key + \`__1\`);
return block1([], [b2]);
}
}"
@@ -46,7 +46,7 @@ exports[`debugging t-debug on sub template 2`] = `
let block1 = createBlock(\`<div><block-child-0/></div>\`);
return function template(ctx, node, key = \\"\\") {
let b2 = callTemplate_2(ctx, node, key + \`__1\`);
let b2 = callTemplate_2.call(this, ctx, node, key + \`__1\`);
return block1([], [b2]);
}
}"
+1 -1
View File
@@ -180,7 +180,7 @@ exports[`t-esc t-esc=0 is escaped 2`] = `
ctx[isBoundary] = 1;
let b2 = block2();
ctx[zero] = b2;
let b3 = callTemplate_2(ctx, node, key + \`__1\`);
let b3 = callTemplate_2.call(this, ctx, node, key + \`__1\`);
return block1([], [b3]);
}
}"
@@ -264,7 +264,7 @@ exports[`t-foreach t-call with body in t-foreach in t-foreach 2`] = `
ctx = Object.create(ctx);
ctx[isBoundary] = 1;
setContextValue(ctx, \\"c\\", 'x'+'_'+ctx['a']+'_'+ctx['b']);
c_block4[i2] = withKey(callTemplate_2(ctx, node, key + \`__1__\${key1}__\${key2}\`), key2);
c_block4[i2] = withKey(callTemplate_2.call(this, ctx, node, key + \`__1__\${key1}__\${key2}\`), key2);
ctx = ctx.__proto__;
}
ctx = ctx.__proto__;
@@ -334,7 +334,7 @@ exports[`t-foreach t-call without body in t-foreach in t-foreach 2`] = `
ctx[\`b_index\`] = i2;
ctx[\`b_value\`] = k_block4[i2];
let key2 = ctx['b'];
c_block4[i2] = withKey(callTemplate_2(ctx, node, key + \`__1__\${key1}__\${key2}\`), key2);
c_block4[i2] = withKey(callTemplate_2.call(this, ctx, node, key + \`__1__\${key1}__\${key2}\`), key2);
}
ctx = ctx.__proto__;
let b4 = list(c_block4);
+1 -1
View File
@@ -58,7 +58,7 @@ exports[`t-raw multiple calls to t-raw 2`] = `
ctx[isBoundary] = 1;
let b2 = block2();
ctx[zero] = b2;
let b3 = callTemplate_2(ctx, node, key + \`__1\`);
let b3 = callTemplate_2.call(this, ctx, node, key + \`__1\`);
return block1([], [b3]);
}
}"
+1 -1
View File
@@ -43,7 +43,7 @@ exports[`t-ref ref in a t-call 1`] = `
let block1 = createBlock(\`<div><block-child-0/></div>\`);
return function template(ctx, node, key = \\"\\") {
let b2 = callTemplate_2(ctx, node, key + \`__1\`);
let b2 = callTemplate_2.call(this, ctx, node, key + \`__1\`);
return block1([], [b2]);
}
}"
+2 -2
View File
@@ -216,7 +216,7 @@ exports[`t-set t-set can't alter from within callee 2`] = `
ctx[isBoundary] = 1
setContextValue(ctx, \\"iter\\", 'source');
let d1 = ctx['iter'];
let b2 = callTemplate_2(ctx, node, key + \`__1\`);
let b2 = callTemplate_2.call(this, ctx, node, key + \`__1\`);
let d2 = ctx['iter'];
return block1([d1, d2], [b2]);
}
@@ -259,7 +259,7 @@ exports[`t-set t-set can't alter in t-call body 2`] = `
ctx = Object.create(ctx);
ctx[isBoundary] = 1;
setContextValue(ctx, \\"iter\\", 'inCall');
let b2 = callTemplate_2(ctx, node, key + \`__1\`);
let b2 = callTemplate_2.call(this, ctx, node, key + \`__1\`);
ctx = ctx.__proto__;
let d2 = ctx['iter'];
return block1([d1, d2], [b2]);
+12 -12
View File
@@ -60,7 +60,7 @@ describe("t-on", () => {
});
test("can bind handlers with arguments", () => {
const template = `<button t-on-click="add(5)">Click</button>`;
const template = `<button t-on-click="() => add(5)">Click</button>`;
let a = 1;
const fixture = mountToFixture(template, { add: (n: number) => (a = a + n) });
expect(a).toBe(1);
@@ -69,7 +69,7 @@ describe("t-on", () => {
});
test("can bind handlers with object arguments", () => {
const template = `<button t-on-click="add({val: 5})">Click</button>`;
const template = `<button t-on-click="() => add({val: 5})">Click</button>`;
let a = 1;
const fixture = mountToFixture(template, { add: ({ val }: any) => (a = a + val) });
expect(a).toBe(1);
@@ -79,7 +79,7 @@ describe("t-on", () => {
test("can bind handlers with empty object", () => {
expect.assertions(2);
const template = `<button t-on-click="doSomething({})">Click</button>`;
const template = `<button t-on-click="() => doSomething({})">Click</button>`;
const fixture = mountToFixture(template, {
doSomething(arg: any) {
expect(arg).toEqual({});
@@ -90,7 +90,7 @@ describe("t-on", () => {
test("can bind handlers with empty object (with non empty inner string)", () => {
expect.assertions(2);
const template = `<button t-on-click="doSomething({ })">Click</button>`;
const template = `<button t-on-click="() => doSomething({ })">Click</button>`;
const fixture = mountToFixture(template, {
doSomething(arg: any) {
expect(arg).toEqual({});
@@ -104,7 +104,7 @@ describe("t-on", () => {
const template = `
<ul>
<li t-foreach="['someval']" t-as="action" t-key="action_index">
<a t-on-click="activate(action)">link</a>
<a t-on-click="() => activate(action)">link</a>
</li>
</ul>`;
const fixture = mountToFixture(template, {
@@ -190,7 +190,7 @@ describe("t-on", () => {
});
test("t-on with inline statement", () => {
const template = `<button t-on-click="state.counter++">Click</button>`;
const template = `<button t-on-click="() => state.counter++">Click</button>`;
let owner = { state: { counter: 0 } };
const fixture = mountToFixture(template, owner);
expect(owner.state.counter).toBe(0);
@@ -199,7 +199,7 @@ describe("t-on", () => {
});
test("t-on with inline statement (function call)", () => {
const template = `<button t-on-click="state.incrementCounter(2)">Click</button>`;
const template = `<button t-on-click="() => state.incrementCounter(2)">Click</button>`;
let owner = {
state: {
counter: 0,
@@ -215,7 +215,7 @@ describe("t-on", () => {
});
test("t-on with inline statement, part 2", () => {
const template = `<button t-on-click="state.flag = !state.flag">Toggle</button>`;
const template = `<button t-on-click="() => state.flag = !state.flag">Toggle</button>`;
let owner = {
state: {
flag: true,
@@ -230,7 +230,7 @@ describe("t-on", () => {
});
test("t-on with inline statement, part 3", () => {
const template = `<button t-on-click="state.n = someFunction(3)">Toggle</button>`;
const template = `<button t-on-click="() => state.n = someFunction(3)">Toggle</button>`;
let owner = {
someFunction(n: number) {
return n + 1;
@@ -272,7 +272,7 @@ describe("t-on", () => {
test("t-on, with arguments and t-call", async () => {
expect.assertions(4);
const app = new TemplateSet();
const sub = `<p t-on-click="update(value)">lucas</p>`;
const sub = `<p t-on-click="() => this.update(value)">lucas</p>`;
const main = `<div><t t-call="sub"/></div>`;
app.addTemplate("sub", sub);
app.addTemplate("main", main);
@@ -290,7 +290,7 @@ describe("t-on", () => {
const fixture = makeTestFixture();
const render = app.getTemplate("main");
const bdom = render(owner, node);
const bdom = render.call(owner, owner, node);
mount(bdom, fixture);
fixture.querySelector("p")!.click();
});
@@ -433,7 +433,7 @@ describe("t-on", () => {
expect.assertions(5);
const template = `<div>
<t t-foreach="projects" t-as="project" t-key="project">
<a href="#" t-on-click.prevent="onEdit(project.id)">
<a href="#" t-on-click.prevent="ev => onEdit(project.id, ev)">
Edit <t t-esc="project.name"/>
</a>
</t>
+5
View File
@@ -169,6 +169,11 @@ describe("expression evaluation", () => {
expect(compileExpr("list.map((elem, index) => elem + index)")).toBe(
"ctx['list'].map((elem,index)=>elem+index)"
);
expect(compileExpr("(ev => ev)(e)")).toBe("(ev=>ev)(ctx['e'])");
});
test.skip("arrow functions: not yet supported", () => {
// e is added to localvars in inline_expression but not removed after the arrow func body
expect(compileExpr("(e => e)(e)")).toBe("(e=>e)(ctx['e'])");
});
test("assignation", () => {