mirror of
https://github.com/odoo/owl.git
synced 2025-10-06 19:59:41 +07:00
[FIX] qweb/component: better handling for t-debug
- fix issue with t-debug on a t-set (defining a slot) - put t-debug and t-log at a very low (high) priority to make sure they are executed before other directives closes #201
This commit is contained in:
+7
-4
@@ -322,10 +322,13 @@ export class QWeb extends EventBus {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
if (isDebug) {
|
if (isDebug) {
|
||||||
console.log(
|
const tpl = this.templates[name];
|
||||||
`Template: ${this.templates[name].elem.outerHTML}\nCompiled code:\n` +
|
if (tpl) {
|
||||||
template.toString()
|
const msg = `Template: ${
|
||||||
);
|
tpl.elem.outerHTML
|
||||||
|
}\nCompiled code:\n${template.toString()}`;
|
||||||
|
console.log(msg);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return template;
|
return template;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -304,7 +304,7 @@ QWeb.addDirective({
|
|||||||
//------------------------------------------------------------------------------
|
//------------------------------------------------------------------------------
|
||||||
QWeb.addDirective({
|
QWeb.addDirective({
|
||||||
name: "debug",
|
name: "debug",
|
||||||
priority: 99,
|
priority: 1,
|
||||||
atNodeEncounter({ ctx }) {
|
atNodeEncounter({ ctx }) {
|
||||||
ctx.addLine("debugger;");
|
ctx.addLine("debugger;");
|
||||||
}
|
}
|
||||||
@@ -315,7 +315,7 @@ QWeb.addDirective({
|
|||||||
//------------------------------------------------------------------------------
|
//------------------------------------------------------------------------------
|
||||||
QWeb.addDirective({
|
QWeb.addDirective({
|
||||||
name: "log",
|
name: "log",
|
||||||
priority: 99,
|
priority: 1,
|
||||||
atNodeEncounter({ ctx, value }) {
|
atNodeEncounter({ ctx, value }) {
|
||||||
const expr = ctx.formatExpression(value);
|
const expr = ctx.formatExpression(value);
|
||||||
ctx.addLine(`console.log(${expr})`);
|
ctx.addLine(`console.log(${expr})`);
|
||||||
|
|||||||
@@ -3093,6 +3093,31 @@ describe("t-slot directive", () => {
|
|||||||
'<div><span><span>some content</span></span></div>'
|
'<div><span><span>some content</span></span></div>'
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test("t-debug on a t-set (defining a slot)", async () => {
|
||||||
|
const consoleLog = console.log;
|
||||||
|
console.log = jest.fn();
|
||||||
|
|
||||||
|
env.qweb.addTemplates(`
|
||||||
|
<templates>
|
||||||
|
<div t-name="Parent">
|
||||||
|
<Dialog><t t-set="content" t-debug="1">abc</t></Dialog>
|
||||||
|
</div>
|
||||||
|
<span t-name="Dialog">
|
||||||
|
<t t-slot="content"/>
|
||||||
|
</span>
|
||||||
|
</templates>
|
||||||
|
`);
|
||||||
|
class Dialog extends Widget {}
|
||||||
|
class Parent extends Widget {
|
||||||
|
components = { Dialog };
|
||||||
|
}
|
||||||
|
const parent = new Parent(env);
|
||||||
|
await parent.mount(fixture);
|
||||||
|
expect(console.log).toHaveBeenCalledTimes(0);
|
||||||
|
console.log = consoleLog;
|
||||||
|
});
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
describe("t-model directive", () => {
|
describe("t-model directive", () => {
|
||||||
|
|||||||
Reference in New Issue
Block a user