mirror of
https://github.com/odoo/owl.git
synced 2025-10-06 19:59:41 +07:00
@@ -81,7 +81,7 @@ const STATIC_TOKEN_MAP: { [key: string]: TKind } = {
|
|||||||
|
|
||||||
// note that the space after typeof is relevant. It makes sure that the formatted
|
// note that the space after typeof is relevant. It makes sure that the formatted
|
||||||
// expression has a space after typeof
|
// expression has a space after typeof
|
||||||
const OPERATORS = ".,===,==,+,!==,!=,!,||,&&,>=,>,<=,<,?,-,*,/,%,typeof ,=>,=,;".split(",");
|
const OPERATORS = "...,.,===,==,+,!==,!=,!,||,&&,>=,>,<=,<,?,-,*,/,%,typeof ,=>,=,;".split(",");
|
||||||
|
|
||||||
type Tokenizer = (expr: string) => Token | false;
|
type Tokenizer = (expr: string) => Token | false;
|
||||||
|
|
||||||
|
|||||||
@@ -5581,14 +5581,14 @@ describe("t-call", () => {
|
|||||||
env.qweb.addTemplate("sub", `<Child/>`);
|
env.qweb.addTemplate("sub", `<Child/>`);
|
||||||
let child;
|
let child;
|
||||||
class Child extends Component<any, any> {
|
class Child extends Component<any, any> {
|
||||||
static template = xml `<span>lucas</span>`
|
static template = xml`<span>lucas</span>`;
|
||||||
constructor() {
|
constructor() {
|
||||||
super(...arguments);
|
super(...arguments);
|
||||||
child = this;
|
child = this;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
class Parent extends Component<any, any> {
|
class Parent extends Component<any, any> {
|
||||||
static components = { Child }
|
static components = { Child };
|
||||||
static template = xml`<div><t t-call="sub"/></div>`;
|
static template = xml`<div><t t-call="sub"/></div>`;
|
||||||
}
|
}
|
||||||
const parent = new Parent();
|
const parent = new Parent();
|
||||||
@@ -5607,10 +5607,10 @@ describe("t-call", () => {
|
|||||||
super(...arguments);
|
super(...arguments);
|
||||||
child = this;
|
child = this;
|
||||||
}
|
}
|
||||||
static template = xml `<span>lucas</span>`
|
static template = xml`<span>lucas</span>`;
|
||||||
}
|
}
|
||||||
class Parent extends Component<any, any> {
|
class Parent extends Component<any, any> {
|
||||||
static components = { Child }
|
static components = { Child };
|
||||||
static template = xml`<t t-call="sub"/>`;
|
static template = xml`<t t-call="sub"/>`;
|
||||||
}
|
}
|
||||||
const parent = new Parent();
|
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`] = `
|
exports[`t-esc t-esc=0 is escaped 1`] = `
|
||||||
"function anonymous(context, extra
|
"function anonymous(context, extra
|
||||||
) {
|
) {
|
||||||
|
|||||||
@@ -141,11 +141,13 @@ describe("t-esc", () => {
|
|||||||
qweb.addTemplate("test", `<span t-esc="var">nope</span>`);
|
qweb.addTemplate("test", `<span t-esc="var">nope</span>`);
|
||||||
expect(renderToString(qweb, "test")).toBe("<span>nope</span>");
|
expect(renderToString(qweb, "test")).toBe("<span>nope</span>");
|
||||||
});
|
});
|
||||||
|
|
||||||
test("t-esc is escaped", () => {
|
test("t-esc is escaped", () => {
|
||||||
qweb.addTemplate("test", `<div><t t-set="var"><p>escaped</p></t><t t-esc="var"/></div>`);
|
qweb.addTemplate("test", `<div><t t-set="var"><p>escaped</p></t><t t-esc="var"/></div>`);
|
||||||
const domRendered = renderToDOM(qweb, "test");
|
const domRendered = renderToDOM(qweb, "test");
|
||||||
expect(domRendered.textContent).toBe("<p>escaped</p>");
|
expect(domRendered.textContent).toBe("<p>escaped</p>");
|
||||||
});
|
});
|
||||||
|
|
||||||
test("t-esc=0 is escaped", () => {
|
test("t-esc=0 is escaped", () => {
|
||||||
qweb.addTemplate("test", `<span><t t-esc="0"/></span>`);
|
qweb.addTemplate("test", `<span><t t-esc="0"/></span>`);
|
||||||
qweb.addTemplate("testCaller", `<div><t t-call="test"><p>escaped</p></t></div>`);
|
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>"
|
"<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", () => {
|
describe("t-raw", () => {
|
||||||
|
|||||||
@@ -50,6 +50,12 @@ describe("tokenizer", () => {
|
|||||||
{ type: "OPERATOR", value: "typeof " },
|
{ type: "OPERATOR", value: "typeof " },
|
||||||
{ type: "SYMBOL", value: "a" }
|
{ type: "SYMBOL", value: "a" }
|
||||||
]);
|
]);
|
||||||
|
|
||||||
|
expect(tokenize("a...1")).toEqual([
|
||||||
|
{ type: "SYMBOL", value: "a" },
|
||||||
|
{ type: "OPERATOR", value: "..." },
|
||||||
|
{ type: "VALUE", value: "1" }
|
||||||
|
]);
|
||||||
});
|
});
|
||||||
|
|
||||||
test("strings", () => {
|
test("strings", () => {
|
||||||
@@ -177,4 +183,10 @@ describe("expression evaluation", () => {
|
|||||||
expect(compileExpr("a -= b", {})).toBe("scope['a']-=scope['b']");
|
expect(compileExpr("a -= b", {})).toBe("scope['a']-=scope['b']");
|
||||||
expect(compileExpr("a.b = !a.b", {})).toBe("scope['a'].b=!scope['a'].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']])");
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user