[FIX] qweb: t-set with a body should not be joined with comma

closes #574
This commit is contained in:
Géry Debongnie
2019-12-13 14:42:10 +01:00
parent 29a80d0b28
commit 0b05ad619f
3 changed files with 49 additions and 6 deletions
+1 -1
View File
@@ -119,7 +119,7 @@ const UTILS: Utils = {
return vnode.text; return vnode.text;
} }
}) })
.join(); .join("");
}, },
getComponent(obj) { getComponent(obj) {
while (obj && !obj.hasOwnProperty("__owl__")) { while (obj && !obj.hasOwnProperty("__owl__")) {
@@ -2965,6 +2965,33 @@ exports[`t-set t-set should reuse variable if possible 1`] = `
}" }"
`; `;
exports[`t-set t-set with content and sub t-esc 1`] = `
"function anonymous(context, extra
) {
// Template name: \\"test\\"
let utils = this.constructor.utils;
let scope = Object.create(context);
let h = this.h;
let c1 = [], p1 = {key:1};
let vn1 = h('div', p1, c1);
let c2 = new utils.VDomArray();
let _3 = scope['beep'];
if (_3 != null) {
c2.push({text: _3});
}
c2.push({text: \` boop\`});
scope.setvar = c2
if (scope.setvar != null) {
let _origScope4 = scope;
scope = Object.assign(Object.create(context), scope);
scope.setvar = scope.setvar instanceof utils.VDomArray ? utils.vDomToString(scope.setvar) : scope.setvar;
c1.push({text: scope.setvar});
scope = _origScope4;
}
return vn1;
}"
`;
exports[`t-set t-set with t-value (falsy) and body 1`] = ` exports[`t-set t-set with t-value (falsy) and body 1`] = `
"function anonymous(context, extra "function anonymous(context, extra
) { ) {
+21 -5
View File
@@ -154,24 +154,28 @@ describe("t-esc", () => {
}); });
test("div with falsy values", () => { test("div with falsy values", () => {
qweb.addTemplate("test", ` qweb.addTemplate(
"test",
`
<div> <div>
<p t-esc="v1"/> <p t-esc="v1"/>
<p t-esc="v2"/> <p t-esc="v2"/>
<p t-esc="v3"/> <p t-esc="v3"/>
<p t-esc="v4"/> <p t-esc="v4"/>
<p t-esc="v5"/> <p t-esc="v5"/>
</div>`); </div>`
);
const vals = { const vals = {
v1: false, v1: false,
v2: undefined, v2: undefined,
v3: null, v3: null,
v4: 0, v4: 0,
v5: "" v5: ""
} };
expect(renderToString(qweb, "test", vals)).toBe("<div><p>false</p><p></p><p></p><p>0</p><p></p></div>"); expect(renderToString(qweb, "test", vals)).toBe(
"<div><p>false</p><p></p><p></p><p>0</p><p></p></div>"
);
}); });
}); });
describe("t-raw", () => { describe("t-raw", () => {
@@ -278,6 +282,18 @@ describe("t-set", () => {
); );
}); });
test("t-set with content and sub t-esc", () => {
qweb.addTemplate(
"test",
`<div>
<t t-set="setvar"><t t-esc="beep"/> boop</t>
<t t-esc="setvar"/>
</div>`
);
expect(renderToString(qweb, "test", { beep: "beep" })).toBe("<div>beep boop</div>");
});
test("evaluate value expression, part 2", () => { test("evaluate value expression, part 2", () => {
qweb.addTemplate( qweb.addTemplate(
"test", "test",