Compare commits

...

3 Commits

Author SHA1 Message Date
Lucas Perais (lpe) e2d86dceb4 TODOOO 2020-01-03 17:45:17 +01:00
Lucas Perais (lpe) 401b2a5b48 oo 2020-01-03 13:01:17 +01:00
Lucas Perais (lpe) 52f027fe46 WIIIP 2020-01-02 14:01:45 +01:00
3 changed files with 45 additions and 0 deletions
+4
View File
@@ -177,6 +177,10 @@ export class CompilationContext {
const protectID = this.generateID();
this.rootContext.shouldDefineScope = true;
this.addLine(`let _origScope${protectID} = scope;`);
this.addLine(`let _origScope${protectID} = scope;`);
// dict of origscopes
// export protectID in compiled string form
// fetch in subsequent code the relevant scope
this.addLine(`scope = Object.assign(Object.create(context), scope);`);
return protectID;
}
+1
View File
@@ -283,6 +283,7 @@ export class QWeb extends EventBus {
fn: function(this: QWeb, context, extra) {
const compiledFunction = this._compile(name, elem);
template.fn = compiledFunction;
console.warn('CompiledFn', compiledFunction.toString());
return compiledFunction.call(this, context, extra);
}
};
+40
View File
@@ -2670,6 +2670,46 @@ describe("other directives with t-component", () => {
await nextTick(); // wait for changes triggered in mounted to be applied
expect(fixture.innerHTML).toBe("<div><span>B0</span><span>B1</span></div>");
});
test.only("t-set outside modified in t-foreach", async () => {
class SomeWidget extends Component<any, any> {
static template = xml`
<div>
<t t-set="iter" t-value="0"/>
<t t-foreach="state.values" t-as="val" t-key="val">
<p>InLoop: <t t-esc="iter"/></p>
<t t-set="iter" t-value="iter + 1"/>
</t>
<p>EndLoop: <t t-esc="iter"/></p>
</div>`;
state = useState({values: ['a', 'b']});
}
const widget = new SomeWidget();
await widget.mount(fixture);
expect(fixture.innerHTML).toBe("<div><p>Inloop: 0</p><p>Inloop: 1</p><p>EndLoop: 2<p></div>");
});
test.only("t-set outside modified in t-foreach increment operator", async () => {
class SomeWidget extends Component<any, any> {
static template = xml`
<div>
<t t-set="iter" t-value="0"/>
<t t-foreach="state.values" t-as="val" t-key="val">
<p>InLoop: <t t-esc="iter"/></p>
<t t-set="iter" t-value="iter++"/>
</t>
<p>EndLoop: <t t-esc="iter"/></p>
</div>`;
state = useState({values: ['a', 'b']});
}
const widget = new SomeWidget();
await widget.mount(fixture);
expect(fixture.innerHTML).toBe("<div><p>Inloop: 0</p><p>Inloop: 1</p><p>EndLoop: 2<p></div>");
});
});
describe("random stuff/miscellaneous", () => {