mirror of
https://github.com/odoo/owl.git
synced 2025-10-06 19:59:41 +07:00
@@ -133,7 +133,7 @@ QWeb.addDirective({
|
|||||||
priority: 20,
|
priority: 20,
|
||||||
atNodeEncounter({ node, ctx }): boolean {
|
atNodeEncounter({ node, ctx }): boolean {
|
||||||
let cond = ctx.getValue(node.getAttribute("t-if")!);
|
let cond = ctx.getValue(node.getAttribute("t-if")!);
|
||||||
ctx.addIf(`${ctx.formatExpression(typeof cond === 'string' ? cond : cond.expr)}`);
|
ctx.addIf(typeof cond === 'string' ? ctx.formatExpression(cond) : cond.id);
|
||||||
return false;
|
return false;
|
||||||
},
|
},
|
||||||
finalize({ ctx }) {
|
finalize({ ctx }) {
|
||||||
@@ -146,7 +146,7 @@ QWeb.addDirective({
|
|||||||
priority: 30,
|
priority: 30,
|
||||||
atNodeEncounter({ node, ctx }): boolean {
|
atNodeEncounter({ node, ctx }): boolean {
|
||||||
let cond = ctx.getValue(node.getAttribute("t-elif")!);
|
let cond = ctx.getValue(node.getAttribute("t-elif")!);
|
||||||
ctx.addLine(`else if (${ctx.formatExpression(typeof cond === 'string' ? cond : cond.expr)}) {`);
|
ctx.addLine(`else if (${typeof cond === 'string' ? ctx.formatExpression(cond) : cond.id}) {`);
|
||||||
ctx.indent();
|
ctx.indent();
|
||||||
return false;
|
return false;
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -1502,6 +1502,30 @@ exports[`t-if t-esc with t-if 1`] = `
|
|||||||
}"
|
}"
|
||||||
`;
|
`;
|
||||||
|
|
||||||
|
exports[`t-if t-set, then t-elif, part 3 1`] = `
|
||||||
|
"function anonymous(context,extra
|
||||||
|
) {
|
||||||
|
var h = this.h;
|
||||||
|
let c1 = [], p1 = {key:1};
|
||||||
|
var vn1 = h('div', p1, c1);
|
||||||
|
var _2 = false;
|
||||||
|
var _3 = _2;
|
||||||
|
if (_3) {
|
||||||
|
let c4 = [], p4 = {key:4};
|
||||||
|
var vn4 = h('span', p4, c4);
|
||||||
|
c1.push(vn4);
|
||||||
|
c4.push({text: \`AAA\`});
|
||||||
|
}
|
||||||
|
else if (!_3) {
|
||||||
|
let c5 = [], p5 = {key:5};
|
||||||
|
var vn5 = h('span', p5, c5);
|
||||||
|
c1.push(vn5);
|
||||||
|
c5.push({text: \`BBB\`});
|
||||||
|
}
|
||||||
|
return vn1;
|
||||||
|
}"
|
||||||
|
`;
|
||||||
|
|
||||||
exports[`t-if t-set, then t-if 1`] = `
|
exports[`t-if t-set, then t-if 1`] = `
|
||||||
"function anonymous(context,extra
|
"function anonymous(context,extra
|
||||||
) {
|
) {
|
||||||
@@ -1509,7 +1533,7 @@ exports[`t-if t-set, then t-if 1`] = `
|
|||||||
let c1 = [], p1 = {key:1};
|
let c1 = [], p1 = {key:1};
|
||||||
var vn1 = h('div', p1, c1);
|
var vn1 = h('div', p1, c1);
|
||||||
var _2 = 'test';
|
var _2 = 'test';
|
||||||
if ('test') {
|
if (_2) {
|
||||||
if (_2 || _2 === 0) {
|
if (_2 || _2 === 0) {
|
||||||
c1.push({text: _2});
|
c1.push({text: _2});
|
||||||
}
|
}
|
||||||
@@ -1518,6 +1542,24 @@ exports[`t-if t-set, then t-if 1`] = `
|
|||||||
}"
|
}"
|
||||||
`;
|
`;
|
||||||
|
|
||||||
|
exports[`t-if t-set, then t-if, part 2 1`] = `
|
||||||
|
"function anonymous(context,extra
|
||||||
|
) {
|
||||||
|
var h = this.h;
|
||||||
|
let c1 = [], p1 = {key:1};
|
||||||
|
var vn1 = h('div', p1, c1);
|
||||||
|
var _2 = true;
|
||||||
|
var _3 = _2;
|
||||||
|
if (_3) {
|
||||||
|
let c4 = [], p4 = {key:4};
|
||||||
|
var vn4 = h('span', p4, c4);
|
||||||
|
c1.push(vn4);
|
||||||
|
c4.push({text: \`COUCOU\`});
|
||||||
|
}
|
||||||
|
return vn1;
|
||||||
|
}"
|
||||||
|
`;
|
||||||
|
|
||||||
exports[`t-key can use t-key directive on a node 1`] = `
|
exports[`t-key can use t-key directive on a node 1`] = `
|
||||||
"function anonymous(context,extra
|
"function anonymous(context,extra
|
||||||
) {
|
) {
|
||||||
|
|||||||
@@ -349,6 +349,32 @@ describe("t-if", () => {
|
|||||||
const expected = `<div>test</div>`;
|
const expected = `<div>test</div>`;
|
||||||
expect(result).toBe(expected);
|
expect(result).toBe(expected);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test("t-set, then t-if, part 2", () => {
|
||||||
|
qweb.addTemplate("test", `
|
||||||
|
<div>
|
||||||
|
<t t-set="y" t-value="true"/>
|
||||||
|
<t t-set="x" t-value="y"/>
|
||||||
|
<span t-if="x">COUCOU</span>
|
||||||
|
</div>`);
|
||||||
|
const result = renderToString(qweb, "test");
|
||||||
|
const expected = `<div><span>COUCOU</span></div>`;
|
||||||
|
expect(result).toBe(expected);
|
||||||
|
});
|
||||||
|
|
||||||
|
test("t-set, then t-elif, part 3", () => {
|
||||||
|
qweb.addTemplate("test", `
|
||||||
|
<div>
|
||||||
|
<t t-set="y" t-value="false"/>
|
||||||
|
<t t-set="x" t-value="y"/>
|
||||||
|
<span t-if="x">AAA</span>
|
||||||
|
<span t-elif="!x">BBB</span>
|
||||||
|
</div>`);
|
||||||
|
const result = renderToString(qweb, "test");
|
||||||
|
const expected = `<div><span>BBB</span></div>`;
|
||||||
|
expect(result).toBe(expected);
|
||||||
|
});
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
describe("attributes", () => {
|
describe("attributes", () => {
|
||||||
|
|||||||
Reference in New Issue
Block a user