From a8b3ec7726b85ea2cfdeb44e02f6fc905e69e51c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?G=C3=A9ry=20Debongnie?= Date: Thu, 21 Mar 2019 10:47:08 +0100 Subject: [PATCH] support using object variables in t-esc --- src/qweb.ts | 2 +- tests/__snapshots__/qweb.test.ts.snap | 14 ++++++++++++++ tests/qweb.test.ts | 9 +++------ 3 files changed, 18 insertions(+), 7 deletions(-) diff --git a/src/qweb.ts b/src/qweb.ts index 9a5c5cf3..17e24ebc 100644 --- a/src/qweb.ts +++ b/src/qweb.ts @@ -469,7 +469,7 @@ export class QWeb { // dynamic attributes if (name.startsWith("t-att-")) { let attName = name.slice(6); - let formattedValue = this._formatExpression(ctx.getValue(value!)); + let formattedValue = this._formatExpression(ctx.getValue(value!), ctx); const attID = ctx.generateID(); if (!attName.match(/^[a-zA-Z]+$/)) { // attribute contains 'non letters' => we want to quote it diff --git a/tests/__snapshots__/qweb.test.ts.snap b/tests/__snapshots__/qweb.test.ts.snap index a89cb29a..73bc86e9 100644 --- a/tests/__snapshots__/qweb.test.ts.snap +++ b/tests/__snapshots__/qweb.test.ts.snap @@ -99,6 +99,20 @@ exports[`attributes format value 1`] = ` }" `; +exports[`attributes from object variables set previously 1`] = ` +"function anonymous(context,extra +) { + let h = this.utils.h; + let c1 = [], p1 = {key:1}; + let vn1 = h('div', p1, c1); + let _2 = {a:'b'}.a; + let c3 = [], p3 = {key:3,attrs:{class: _2}}; + let vn3 = h('span', p3, c3); + c1.push(vn3); + return vn1; +}" +`; + exports[`attributes from variables set previously 1`] = ` "function anonymous(context,extra ) { diff --git a/tests/qweb.test.ts b/tests/qweb.test.ts index 0461c496..12d05837 100644 --- a/tests/qweb.test.ts +++ b/tests/qweb.test.ts @@ -410,14 +410,11 @@ describe("attributes", () => { expect(result).toBe('
'); }); - test.skip("from object variables set previously", () => { - // qweb is stupid and does not support this. - // To do that properly, we need to extend the formatExpression method to - // be able to deal with objects. I think that it is not easy: - // it should properly deal with stuff like {a:expr, b: {c: otherexpr}} + test("from object variables set previously", () => { + // Note: standard qweb does not allow this... qweb.addTemplate( "test", - `
` + `
` ); const result = renderToString(qweb, "test"); expect(result).toBe('
');