[FIX] qweb: fix issue variables set in body of t-call

The body of a t-call directive may be used to define private variables
to the sub template call.

However, the code that handles t-call worked like this:

- compile sub template if necessary
- then compile body of t-call to extract variables

This means that the variables defined in the t-call body were not yet
processed and available in the context.  Because of that, when the call
to t-esc is done, there is not internal qweb var, and the code simply
outputs a scope['varname'], which is in our case a VDOMArray, so it is
displayed as [object object]

What this fix does is changing the way t-esc works: if we are in the
context of a sub template, then it assumes that any outside variable may
or may not be a VDomArray, so it needs to check and eventually convert
it to a string, if necessary.

closes #719
This commit is contained in:
Géry Debongnie
2020-09-16 09:58:57 +02:00
committed by aab-odoo
parent 2529aa3ef2
commit 3bf91afc3f
5 changed files with 56 additions and 2 deletions
+7 -1
View File
@@ -41,6 +41,12 @@ function compileValueNode(value: any, node: Element, qweb: QWeb, ctx: Compilatio
if (typeof value === "string") {
exprID = `_${ctx.generateID()}`;
ctx.addLine(`let ${exprID} = ${ctx.formatExpression(value)};`);
if (ctx.isSubTemplate) {
ctx.rootContext.shouldDefineUtils = true;
ctx.addLine(
`${exprID} = ${exprID} instanceof utils.VDomArray ? utils.vDomToString(${exprID}) : ${exprID};`
);
}
} else {
exprID = `scope.${value.id}`;
}
@@ -238,7 +244,7 @@ QWeb.addDirective({
if (!subId) {
subId = QWeb.nextId++;
qweb.subTemplates[subTemplate] = subId;
const subTemplateFn = qweb._compile(subTemplate, nodeTemplate.elem, ctx, true);
const subTemplateFn = qweb._compile(subTemplate, nodeTemplate.elem, ctx, true, true);
QWeb.subTemplates[subId] = subTemplateFn;
}
+1
View File
@@ -22,6 +22,7 @@ export class CompilationContext {
shouldDefineUtils: boolean = false;
shouldDefineRefs: boolean = false;
shouldDefineResult: boolean = true;
isSubTemplate: boolean = false;
loopNumber: number = 0;
inPreTag: boolean = false;
templateName: string;
+3 -1
View File
@@ -413,10 +413,12 @@ export class QWeb extends EventBus {
name: string,
elem: Element,
parentContext?: CompilationContext,
defineKey?: boolean
defineKey?: boolean,
isSubTemplate?: boolean
): CompiledTemplate {
const isDebug = elem.attributes.hasOwnProperty("t-debug");
const ctx = new CompilationContext(name);
ctx.isSubTemplate = Boolean(isSubTemplate);
if (elem.tagName !== "t") {
ctx.shouldDefineResult = false;
}