[FIX] compiler: add support for #{...} in string interpolation

This commit is contained in:
Géry Debongnie
2022-06-07 17:25:23 +02:00
committed by Sam Degueldre
parent a3111eb9ca
commit 385e118e58
7 changed files with 68 additions and 14 deletions
@@ -387,6 +387,20 @@ exports[`attributes static attributes with dashes 1`] = `
}"
`;
exports[`attributes string interpolation, alternate syntax 1`] = `
"function anonymous(app, bdom, helpers
) {
let { text, createBlock, list, multi, html, toggler, component, comment } = bdom;
let block1 = createBlock(\`<div block-attribute-0=\\"foo\\"/>\`);
return function template(ctx, node, key = \\"\\") {
let attr1 = \`b\${ctx['value']}r\`;
return block1([attr1]);
}
}"
`;
exports[`attributes t-att-class and class should combine together 1`] = `
"function anonymous(app, bdom, helpers
) {
@@ -16,6 +16,22 @@ exports[`t-ref can get a dynamic ref on a node 1`] = `
}"
`;
exports[`t-ref can get a dynamic ref on a node, alternate syntax 1`] = `
"function anonymous(app, bdom, helpers
) {
let { text, createBlock, list, multi, html, toggler, component, comment } = bdom;
let block1 = createBlock(\`<div><span block-ref=\\"0\\"/></div>\`);
return function template(ctx, node, key = \\"\\") {
const refs = ctx.__owl__.refs;
const v1 = ctx['id'];
let ref1 = (el) => refs[\`myspan\${v1}\`] = el;
return block1([ref1]);
}
}"
`;
exports[`t-ref can get a ref on a node 1`] = `
"function anonymous(app, bdom, helpers
) {
@@ -99,7 +115,7 @@ exports[`t-ref refs in a loop 1`] = `
const key1 = ctx['item'];
const tKey_1 = ctx['item'];
const v1 = ctx['item'];
let ref1 = (el) => refs[\`\${v1}\`] = el;
let ref1 = (el) => refs[(v1)] = el;
let txt1 = ctx['item'];
c_block2[i1] = withKey(block3([ref1, txt1]), tKey_1 + key1);
}
+6
View File
@@ -131,6 +131,12 @@ describe("attributes", () => {
expect(result).toBe(`<div foo="bar"></div>`);
});
test("string interpolation, alternate syntax", () => {
const template = `<div t-attf-foo="b#{value}r"/>`;
const result = renderToString(template, { value: "a" });
expect(result).toBe(`<div foo="bar"></div>`);
});
test("t-attf-class", () => {
const template = `<div t-attf-class="hello"/>`;
const result = renderToString(template);
+9
View File
@@ -27,6 +27,15 @@ describe("t-ref", () => {
expect(refs.myspan3.tagName).toBe("SPAN");
});
test("can get a dynamic ref on a node, alternate syntax", () => {
const template = `<div><span t-ref="myspan#{id}"/></div>`;
const refs: any = {};
const bdom = renderToBdom(template, { id: 3, __owl__: { refs } });
expect(refs).toEqual({});
mount(bdom, document.createElement("div"));
expect(refs.myspan3.tagName).toBe("SPAN");
});
test("refs in a loop", () => {
const template = `<div>
<t t-foreach="items" t-as="item" t-key="item">