[FIX] qweb: add support for spread operator

closes #575
This commit is contained in:
Géry Debongnie
2019-12-13 14:50:49 +01:00
committed by aab-odoo
parent 455e45c148
commit ef6fd457f8
5 changed files with 41 additions and 5 deletions
+4 -4
View File
@@ -5581,14 +5581,14 @@ describe("t-call", () => {
env.qweb.addTemplate("sub", `<Child/>`);
let child;
class Child extends Component<any, any> {
static template = xml `<span>lucas</span>`
static template = xml`<span>lucas</span>`;
constructor() {
super(...arguments);
child = this;
}
}
class Parent extends Component<any, any> {
static components = { Child }
static components = { Child };
static template = xml`<div><t t-call="sub"/></div>`;
}
const parent = new Parent();
@@ -5607,10 +5607,10 @@ describe("t-call", () => {
super(...arguments);
child = this;
}
static template = xml `<span>lucas</span>`
static template = xml`<span>lucas</span>`;
}
class Parent extends Component<any, any> {
static components = { Child }
static components = { Child };
static template = xml`<t t-call="sub"/>`;
}
const parent = new Parent();
@@ -1772,6 +1772,22 @@ exports[`t-esc t-esc is escaped 1`] = `
}"
`;
exports[`t-esc t-esc work with spread operator 1`] = `
"function anonymous(context, extra
) {
// Template name: \\"test\\"
let scope = Object.create(context);
let h = this.h;
let c1 = [], p1 = {key:1};
let vn1 = h('span', p1, c1);
let _2 = [...scope['state'].list];
if (_2 != null) {
c1.push({text: _2});
}
return vn1;
}"
`;
exports[`t-esc t-esc=0 is escaped 1`] = `
"function anonymous(context, extra
) {
+8
View File
@@ -141,11 +141,13 @@ describe("t-esc", () => {
qweb.addTemplate("test", `<span t-esc="var">nope</span>`);
expect(renderToString(qweb, "test")).toBe("<span>nope</span>");
});
test("t-esc is escaped", () => {
qweb.addTemplate("test", `<div><t t-set="var"><p>escaped</p></t><t t-esc="var"/></div>`);
const domRendered = renderToDOM(qweb, "test");
expect(domRendered.textContent).toBe("<p>escaped</p>");
});
test("t-esc=0 is escaped", () => {
qweb.addTemplate("test", `<span><t t-esc="0"/></span>`);
qweb.addTemplate("testCaller", `<div><t t-call="test"><p>escaped</p></t></div>`);
@@ -176,6 +178,12 @@ describe("t-esc", () => {
"<div><p>false</p><p></p><p></p><p>0</p><p></p></div>"
);
});
test("t-esc work with spread operator", () => {
qweb.addTemplate("test", `<span><t t-esc="[...state.list]"/></span>`);
const result = renderToString(qweb, "test", { state: { list: [1, 2] } });
expect(result).toBe("<span>1,2</span>");
});
});
describe("t-raw", () => {
+12
View File
@@ -50,6 +50,12 @@ describe("tokenizer", () => {
{ type: "OPERATOR", value: "typeof " },
{ type: "SYMBOL", value: "a" }
]);
expect(tokenize("a...1")).toEqual([
{ type: "SYMBOL", value: "a" },
{ type: "OPERATOR", value: "..." },
{ type: "VALUE", value: "1" }
]);
});
test("strings", () => {
@@ -177,4 +183,10 @@ describe("expression evaluation", () => {
expect(compileExpr("a -= b", {})).toBe("scope['a']-=scope['b']");
expect(compileExpr("a.b = !a.b", {})).toBe("scope['a'].b=!scope['a'].b");
});
test("spread operator", () => {
expect(compileExpr("[...state.list]", {})).toBe("[...scope['state'].list]");
expect(compileExpr("f(...state.list)", {})).toBe("scope['f'](...scope['state'].list)");
expect(compileExpr("f([...list])", {})).toBe("scope['f']([...scope['list']])");
});
});