fix context issue after loop t-foreach

This commit is contained in:
Géry Debongnie
2019-01-30 13:33:37 +01:00
parent 68973b3321
commit 4e4702c6cf
2 changed files with 23 additions and 1 deletions
+7 -1
View File
@@ -59,6 +59,12 @@ export class Context {
return newContext;
}
withInLoop(): Context {
const newContext = Object.create(this);
newContext.inLoop = true;
return newContext;
}
withCaller(node: Element): Context {
const newContext = Object.create(this);
newContext.caller = node;
@@ -629,7 +635,7 @@ const forEachDirective: Directive = {
priority: 10,
atNodeEncounter({ node, qweb, ctx }): boolean {
ctx.rootContext.shouldProtectContext = true;
ctx.inLoop = true;
ctx = ctx.withInLoop();
const elems = node.getAttribute("t-foreach")!;
const name = node.getAttribute("t-as")!;
let arrayID = ctx.generateID();
+16
View File
@@ -698,3 +698,19 @@ describe("props evaluation (with t-props directive)", () => {
expect(fixture.innerHTML).toBe("<div><span>42</span></div>");
});
});
describe("random stuff", () => {
test("widget after a t-foreach", async () => {
// this test makes sure that the foreach directive does not pollute sub
// context with the inLoop variable, which is then used in the t-widget
// directive as a key
class Test extends Widget<WEnv, {}> {
name = "test";
template = `<div><t t-foreach="2">txt</t><t t-widget="widget"/></div>`;
widgets = { widget: Widget };
}
const widget = new Test(env);
await widget.mount(fixture);
expect(fixture.innerHTML).toBe("<div>txttxt<div></div></div>");
});
});