[IMP] compiler: improve generated compiled code

This commit is contained in:
Géry Debongnie
2021-12-22 11:33:12 +01:00
committed by Aaron Bohy
parent bd5637c0a3
commit c7af885f43
36 changed files with 939 additions and 936 deletions
@@ -8,8 +8,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'], ctx];
return block1([d1]);
let hdlr1 = [ctx['add'], ctx];
return block1([hdlr1]);
}
}"
`;
@@ -23,8 +23,8 @@ exports[`t-on can bind handlers with arguments 1`] = `
return function template(ctx, node, key = \\"\\") {
const v1 = ctx['add'];
let d1 = [()=>v1(5), ctx];
return block1([d1]);
let hdlr1 = [()=>v1(5), ctx];
return block1([hdlr1]);
}
}"
`;
@@ -38,8 +38,8 @@ exports[`t-on can bind handlers with empty object 1`] = `
return function template(ctx, node, key = \\"\\") {
const v1 = ctx['doSomething'];
let d1 = [()=>v1({}), ctx];
return block1([d1]);
let hdlr1 = [()=>v1({}), ctx];
return block1([hdlr1]);
}
}"
`;
@@ -53,8 +53,8 @@ exports[`t-on can bind handlers with empty object (with non empty inner string)
return function template(ctx, node, key = \\"\\") {
const v1 = ctx['doSomething'];
let d1 = [()=>v1({}), ctx];
return block1([d1]);
let hdlr1 = [()=>v1({}), ctx];
return block1([hdlr1]);
}
}"
`;
@@ -77,8 +77,8 @@ exports[`t-on can bind handlers with empty object (with non empty inner string)
let key1 = ctx['action_index'];
const v1 = ctx['activate'];
const v2 = ctx['action'];
let d1 = [()=>v1(v2), ctx];
c_block2[i1] = withKey(block3([d1]), key1);
let hdlr1 = [()=>v1(v2), ctx];
c_block2[i1] = withKey(block3([hdlr1]), key1);
}
let b2 = list(c_block2);
return block1([], [b2]);
@@ -95,8 +95,8 @@ exports[`t-on can bind handlers with object arguments 1`] = `
return function template(ctx, node, key = \\"\\") {
const v1 = ctx['add'];
let d1 = [()=>v1({val:5}), ctx];
return block1([d1]);
let hdlr1 = [()=>v1({val:5}), ctx];
return block1([hdlr1]);
}
}"
`;
@@ -109,9 +109,9 @@ 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'], ctx];
let d2 = [ctx['handleDblClick'], ctx];
return block1([d1, d2]);
let hdlr1 = [ctx['handleClick'], ctx];
let hdlr2 = [ctx['handleDblClick'], ctx];
return block1([hdlr1, hdlr2]);
}
}"
`;
@@ -124,8 +124,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'], ctx];
return block1([d1]);
let hdlr1 = [ctx['add'], ctx];
return block1([hdlr1]);
}
}"
`;
@@ -144,8 +144,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'], ctx];
c_block1[i1] = withKey(block2([d1]), key1);
let hdlr1 = [ctx['add'], ctx];
c_block1[i1] = withKey(block2([hdlr1]), key1);
}
return list(c_block1);
}
@@ -173,8 +173,8 @@ exports[`t-on handler is bound to proper owner, part 3 2`] = `
let block1 = createBlock(\`<button block-handler-0=\\"click\\">Click</button>\`);
return function template(ctx, node, key = \\"\\") {
let d1 = [ctx['add'], ctx];
return block1([d1]);
let hdlr1 = [ctx['add'], ctx];
return block1([hdlr1]);
}
}"
`;
@@ -211,8 +211,8 @@ exports[`t-on handler is bound to proper owner, part 4 2`] = `
let block1 = createBlock(\`<button block-handler-0=\\"click\\">Click</button>\`);
return function template(ctx, node, key = \\"\\") {
let d1 = [ctx['add'], ctx];
return block1([d1]);
let hdlr1 = [ctx['add'], ctx];
return block1([hdlr1]);
}
}"
`;
@@ -225,8 +225,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'], ctx];
return block1([d1]);
let hdlr1 = [ctx['add'], ctx];
return block1([hdlr1]);
}
}"
`;
@@ -239,9 +239,9 @@ 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'], ctx];
let d2 = [ctx['btnClicked'], ctx];
return block1([d1, d2]);
let hdlr1 = [ctx['divClicked'], ctx];
let hdlr2 = [ctx['btnClicked'], ctx];
return block1([hdlr1, hdlr2]);
}
}"
`;
@@ -254,9 +254,9 @@ 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'], ctx];
let d2 = ctx['text'];
return block1([d1, d2]);
let hdlr1 = [ctx['onClick'], ctx];
let txt2 = ctx['text'];
return block1([hdlr1, txt2]);
}
}"
`;
@@ -270,9 +270,9 @@ exports[`t-on t-on modifiers (native listener) t-on combined with t-out 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'], ctx];
let hdlr1 = [ctx['onClick'], ctx];
let b2 = safeOutput(ctx['html']);
return block1([d1], [b2]);
return block1([hdlr1], [b2]);
}
}"
`;
@@ -285,9 +285,9 @@ 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'], ctx];
let d2 = [ctx['doSomething'], ctx];
return block1([d1, d2]);
let hdlr1 = [\\"capture\\", ctx['onCapture'], ctx];
let hdlr2 = [ctx['doSomething'], ctx];
return block1([hdlr1, hdlr2]);
}
}"
`;
@@ -300,8 +300,8 @@ 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\\", , ctx];
return block1([d1]);
let hdlr1 = [\\"prevent\\", , ctx];
return block1([hdlr1]);
}
}"
`;
@@ -314,8 +314,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'], ctx];
return block1([d1]);
let hdlr1 = [\\"prevent\\",\\"self\\", ctx['onClick'], ctx];
return block1([hdlr1]);
}
}"
`;
@@ -328,10 +328,10 @@ 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'], ctx];
let d2 = [\\"stop\\", ctx['onClickStopped'], ctx];
let d3 = [\\"prevent\\",\\"stop\\", ctx['onClickPreventedAndStopped'], ctx];
return block1([d1, d2, d3]);
let hdlr1 = [\\"prevent\\", ctx['onClickPrevented'], ctx];
let hdlr2 = [\\"stop\\", ctx['onClickStopped'], ctx];
let hdlr3 = [\\"prevent\\",\\"stop\\", ctx['onClickPreventedAndStopped'], ctx];
return block1([hdlr1, hdlr2, hdlr3]);
}
}"
`;
@@ -353,9 +353,9 @@ exports[`t-on t-on modifiers (native listener) t-on with prevent modifier in t-f
let key1 = ctx['project'];
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);
let hdlr1 = [\\"prevent\\", ev=>v1(v2.id,ev), ctx];
let txt2 = ctx['project'].name;
c_block2[i1] = withKey(block3([hdlr1, txt2]), key1);
}
let b2 = list(c_block2);
return block1([], [b2]);
@@ -371,8 +371,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'], ctx];
return block1([d1]);
let hdlr1 = [\\"self\\",\\"prevent\\", ctx['onClick'], ctx];
return block1([hdlr1]);
}
}"
`;
@@ -385,9 +385,9 @@ 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'], ctx];
let d2 = [\\"self\\", ctx['onClickSelf'], ctx];
return block1([d1, d2]);
let hdlr1 = [ctx['onClick'], ctx];
let hdlr2 = [\\"self\\", ctx['onClickSelf'], ctx];
return block1([hdlr1, hdlr2]);
}
}"
`;
@@ -400,9 +400,9 @@ 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'], ctx];
let d2 = [\\"synthetic\\", ctx['btnClicked'], ctx];
return block1([d1, d2]);
let hdlr1 = [\\"synthetic\\", ctx['divClicked'], ctx];
let hdlr2 = [\\"synthetic\\", ctx['btnClicked'], ctx];
return block1([hdlr1, hdlr2]);
}
}"
`;
@@ -416,8 +416,8 @@ exports[`t-on t-on with inline statement (function call) 1`] = `
return function template(ctx, node, key = \\"\\") {
const v1 = ctx['state'];
let d1 = [()=>v1.incrementCounter(2), ctx];
return block1([d1]);
let hdlr1 = [()=>v1.incrementCounter(2), ctx];
return block1([hdlr1]);
}
}"
`;
@@ -431,8 +431,8 @@ exports[`t-on t-on with inline statement 1`] = `
return function template(ctx, node, key = \\"\\") {
const v1 = ctx['state'];
let d1 = [()=>v1.counter++, ctx];
return block1([d1]);
let hdlr1 = [()=>v1.counter++, ctx];
return block1([hdlr1]);
}
}"
`;
@@ -446,8 +446,8 @@ exports[`t-on t-on with inline statement, part 2 1`] = `
return function template(ctx, node, key = \\"\\") {
const v1 = ctx['state'];
let d1 = [()=>v1.flag=!v1.flag, ctx];
return block1([d1]);
let hdlr1 = [()=>v1.flag=!v1.flag, ctx];
return block1([hdlr1]);
}
}"
`;
@@ -462,8 +462,8 @@ 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 = [()=>v1.n=v2(3), ctx];
return block1([d1]);
let hdlr1 = [()=>v1.n=v2(3), ctx];
return block1([hdlr1]);
}
}"
`;
@@ -492,8 +492,8 @@ exports[`t-on t-on with t-call 2`] = `
let block1 = createBlock(\`<p block-handler-0=\\"click\\">lucas</p>\`);
return function template(ctx, node, key = \\"\\") {
let d1 = [ctx['update'], ctx];
return block1([d1]);
let hdlr1 = [ctx['update'], ctx];
return block1([hdlr1]);
}
}"
`;
@@ -523,8 +523,8 @@ exports[`t-on t-on, with arguments and t-call 2`] = `
return function template(ctx, node, key = \\"\\") {
const v1 = ctx['value'];
let d1 = [()=>this.update(v1), ctx];
return block1([d1]);
let hdlr1 = [()=>this.update(v1), ctx];
return block1([hdlr1]);
}
}"
`;