[FIX] qweb: t-set should reuse variable if possible

closes #41
This commit is contained in:
Géry Debongnie
2019-04-16 16:04:44 +02:00
parent cef12acfe0
commit c52e86feaf
3 changed files with 60 additions and 4 deletions
+8 -4
View File
@@ -782,11 +782,15 @@ const setDirective: Directive = {
const variable = node.getAttribute("t-set")!;
let value = node.getAttribute("t-value")!;
if (value) {
const varName = `_${ctx.generateID()}`;
const formattedValue = ctx.formatExpression(value);
ctx.addLine(`var ${varName} = ${formattedValue}`);
ctx.definedVariables[varName] = formattedValue;
ctx.variables[variable] = varName;
if (ctx.variables.hasOwnProperty(variable)) {
ctx.addLine(`${ctx.variables[variable]} = ${formattedValue}`);
} else {
const varName = `_${ctx.generateID()}`;
ctx.addLine(`var ${varName} = ${formattedValue}`);
ctx.definedVariables[varName] = formattedValue;
ctx.variables[variable] = varName;
}
} else {
ctx.variables[variable] = node.childNodes;
}