diff --git a/src/qweb/base_directives.ts b/src/qweb/base_directives.ts index 804236c3..44265006 100644 --- a/src/qweb/base_directives.ts +++ b/src/qweb/base_directives.ts @@ -133,7 +133,7 @@ QWeb.addDirective({ priority: 20, atNodeEncounter({ node, ctx }): boolean { 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; }, finalize({ ctx }) { @@ -146,7 +146,7 @@ QWeb.addDirective({ priority: 30, atNodeEncounter({ node, ctx }): boolean { 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(); return false; }, diff --git a/tests/qweb/__snapshots__/qweb.test.ts.snap b/tests/qweb/__snapshots__/qweb.test.ts.snap index 0050e242..e0cf231d 100644 --- a/tests/qweb/__snapshots__/qweb.test.ts.snap +++ b/tests/qweb/__snapshots__/qweb.test.ts.snap @@ -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`] = ` "function anonymous(context,extra ) { @@ -1509,7 +1533,7 @@ exports[`t-if t-set, then t-if 1`] = ` let c1 = [], p1 = {key:1}; var vn1 = h('div', p1, c1); var _2 = 'test'; - if ('test') { + if (_2) { if (_2 || _2 === 0) { 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`] = ` "function anonymous(context,extra ) { diff --git a/tests/qweb/qweb.test.ts b/tests/qweb/qweb.test.ts index fa902500..5f3ae2a1 100644 --- a/tests/qweb/qweb.test.ts +++ b/tests/qweb/qweb.test.ts @@ -349,6 +349,32 @@ describe("t-if", () => { const expected = `