mirror of
https://github.com/odoo/owl.git
synced 2025-10-06 19:59:41 +07:00
[FIX] compiler: add _ prefix to local variables while compiling an expression
This commit is contained in:
@@ -353,7 +353,7 @@ 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 hdlr1 = [\\"prevent\\", ev=>v1(v2.id,ev), ctx];
|
||||
let hdlr1 = [\\"prevent\\", _ev=>v1(v2.id,_ev), ctx];
|
||||
let txt1 = ctx['project'].name;
|
||||
c_block2[i1] = withKey(block3([hdlr1, txt1]), key1);
|
||||
}
|
||||
|
||||
@@ -30,7 +30,7 @@ exports[`misc complex template 1`] = `
|
||||
b3 = block3();
|
||||
}
|
||||
ctx = Object.create(ctx);
|
||||
const [k_block4, v_block4, l_block4, c_block4] = prepareList(ctx['batch'].slot_ids.filter(slot=>slot.build_id.id&&!slot.trigger_id.manual&&(ctx['options'].trigger_display[slot.trigger_id.id])));
|
||||
const [k_block4, v_block4, l_block4, c_block4] = prepareList(ctx['batch'].slot_ids.filter(_slot=>_slot.build_id.id&&!_slot.trigger_id.manual&&(ctx['options'].trigger_display[_slot.trigger_id.id])));
|
||||
for (let i1 = 0; i1 < l_block4; i1++) {
|
||||
ctx[\`slot\`] = v_block4[i1];
|
||||
let key1 = ctx['slot'].id;
|
||||
|
||||
@@ -163,17 +163,18 @@ describe("expression evaluation", () => {
|
||||
});
|
||||
|
||||
test("arrow functions", () => {
|
||||
expect(compileExpr("list.map(e => e.val)")).toBe("ctx['list'].map(e=>e.val)");
|
||||
expect(compileExpr("list.map(e => a + e)")).toBe("ctx['list'].map(e=>ctx['a']+e)");
|
||||
expect(compileExpr("list.map((e) => e)")).toBe("ctx['list'].map((e)=>e)");
|
||||
expect(compileExpr("list.map(e => e.val)")).toBe("ctx['list'].map(_e=>_e.val)");
|
||||
expect(compileExpr("list.map(e => a + e)")).toBe("ctx['list'].map(_e=>ctx['a']+_e)");
|
||||
expect(compileExpr("list.map((e) => e)")).toBe("ctx['list'].map((_e)=>_e)");
|
||||
expect(compileExpr("list.map((elem, index) => elem + index)")).toBe(
|
||||
"ctx['list'].map((elem,index)=>elem+index)"
|
||||
"ctx['list'].map((_elem,_index)=>_elem+_index)"
|
||||
);
|
||||
expect(compileExpr("(ev => ev)(e)")).toBe("(ev=>ev)(ctx['e'])");
|
||||
expect(compileExpr("(ev => ev)(e)")).toBe("(_ev=>_ev)(ctx['e'])");
|
||||
expect(compileExpr("(v1) => myFunc(v1)")).toBe("(_v1)=>ctx['myFunc'](_v1)");
|
||||
});
|
||||
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'])");
|
||||
expect(compileExpr("(e => e)(e)")).toBe("(_e=>_e)(ctx['e'])");
|
||||
});
|
||||
|
||||
test("assignation", () => {
|
||||
|
||||
Reference in New Issue
Block a user