Files
owl/tests/compiler/__snapshots__/simple_templates.test.ts.snap
T
Samuel Degueldre 11e4e67599 [FIX] compiler: correctly escape special characters in template literals
Previously, there were a few places where the compiler would create
strings from template content and emit them as template literals, but
didn't properly escape characters or character sequences with special
meanings, in particular: backslashes, backticks, and interpolation
sigils.

This commit fixes this in:
- block creation (interpolation sigils were not escaped)
- text node creation (no escaping was performed)
- comment not creation (no escaping was performed)
- default values for t-esc (no escaping was performed)
- body of a t-set (no escaping was performed)
2024-05-13 15:35:02 +02:00

417 lines
11 KiB
Plaintext

// Jest Snapshot v1, https://goo.gl/fbAQLP
exports[`simple templates, mostly static can render a table row 1`] = `
"function anonymous(app, bdom, helpers
) {
let { text, createBlock, list, multi, html, toggler, comment } = bdom;
let block1 = createBlock(\`<tr><td>cell</td></tr>\`);
return function template(ctx, node, key = \\"\\") {
return block1();
}
}"
`;
exports[`simple templates, mostly static div with a class attribute 1`] = `
"function anonymous(app, bdom, helpers
) {
let { text, createBlock, list, multi, html, toggler, comment } = bdom;
let block1 = createBlock(\`<div class=\\"abc\\">foo</div>\`);
return function template(ctx, node, key = \\"\\") {
return block1();
}
}"
`;
exports[`simple templates, mostly static div with a class attribute with a quote 1`] = `
"function anonymous(app, bdom, helpers
) {
let { text, createBlock, list, multi, html, toggler, comment } = bdom;
let block1 = createBlock(\`<div class=\\"a'bc\\">word</div>\`);
return function template(ctx, node, key = \\"\\") {
return block1();
}
}"
`;
exports[`simple templates, mostly static div with a span child node 1`] = `
"function anonymous(app, bdom, helpers
) {
let { text, createBlock, list, multi, html, toggler, comment } = bdom;
let block1 = createBlock(\`<div><span>word</span></div>\`);
return function template(ctx, node, key = \\"\\") {
return block1();
}
}"
`;
exports[`simple templates, mostly static div with an arbitrary attribute with a quote 1`] = `
"function anonymous(app, bdom, helpers
) {
let { text, createBlock, list, multi, html, toggler, comment } = bdom;
let block1 = createBlock(\`<div abc=\\"a'bc\\">word</div>\`);
return function template(ctx, node, key = \\"\\") {
return block1();
}
}"
`;
exports[`simple templates, mostly static div with an empty class attribute 1`] = `
"function anonymous(app, bdom, helpers
) {
let { text, createBlock, list, multi, html, toggler, comment } = bdom;
let block1 = createBlock(\`<div>word</div>\`);
return function template(ctx, node, key = \\"\\") {
return block1();
}
}"
`;
exports[`simple templates, mostly static div with content 1`] = `
"function anonymous(app, bdom, helpers
) {
let { text, createBlock, list, multi, html, toggler, comment } = bdom;
let block1 = createBlock(\`<div>foo</div>\`);
return function template(ctx, node, key = \\"\\") {
return block1();
}
}"
`;
exports[`simple templates, mostly static dom node with t-esc 1`] = `
"function anonymous(app, bdom, helpers
) {
let { text, createBlock, list, multi, html, toggler, comment } = bdom;
let block1 = createBlock(\`<div><block-text-0/></div>\`);
return function template(ctx, node, key = \\"\\") {
let txt1 = ctx['text'];
return block1([txt1]);
}
}"
`;
exports[`simple templates, mostly static dom node with t-esc 2`] = `
"function anonymous(app, bdom, helpers
) {
let { text, createBlock, list, multi, html, toggler, comment } = bdom;
let block1 = createBlock(\`<div><block-text-0/></div>\`);
return function template(ctx, node, key = \\"\\") {
let txt1 = ctx['text'];
return block1([txt1]);
}
}"
`;
exports[`simple templates, mostly static dynamic text value 1`] = `
"function anonymous(app, bdom, helpers
) {
let { text, createBlock, list, multi, html, toggler, comment } = bdom;
return function template(ctx, node, key = \\"\\") {
return text(ctx['text']);
}
}"
`;
exports[`simple templates, mostly static empty div 1`] = `
"function anonymous(app, bdom, helpers
) {
let { text, createBlock, list, multi, html, toggler, comment } = bdom;
let block1 = createBlock(\`<div/>\`);
return function template(ctx, node, key = \\"\\") {
return block1();
}
}"
`;
exports[`simple templates, mostly static empty string 1`] = `
"function anonymous(app, bdom, helpers
) {
let { text, createBlock, list, multi, html, toggler, comment } = bdom;
return function template(ctx, node, key = \\"\\") {
return text(\`\`);
}
}"
`;
exports[`simple templates, mostly static empty string in a template set 1`] = `
"function anonymous(app, bdom, helpers
) {
let { text, createBlock, list, multi, html, toggler, comment } = bdom;
return function template(ctx, node, key = \\"\\") {
return text(\`\`);
}
}"
`;
exports[`simple templates, mostly static inline template string in t-esc 1`] = `
"function anonymous(app, bdom, helpers
) {
let { text, createBlock, list, multi, html, toggler, comment } = bdom;
return function template(ctx, node, key = \\"\\") {
return text(\`text\`);
}
}"
`;
exports[`simple templates, mostly static inline template string with content in t-esc 1`] = `
"function anonymous(app, bdom, helpers
) {
let { text, createBlock, list, multi, html, toggler, comment } = bdom;
let { isBoundary, withDefault, setContextValue } = helpers;
return function template(ctx, node, key = \\"\\") {
ctx = Object.create(ctx);
ctx[isBoundary] = 1
setContextValue(ctx, \\"v\\", 1);
return text(\`text\${ctx['v']}\`);
}
}"
`;
exports[`simple templates, mostly static inline template string with variable in context 1`] = `
"function anonymous(app, bdom, helpers
) {
let { text, createBlock, list, multi, html, toggler, comment } = bdom;
return function template(ctx, node, key = \\"\\") {
return text(\`text \${ctx['v']}\`);
}
}"
`;
exports[`simple templates, mostly static multiple root nodes 1`] = `
"function anonymous(app, bdom, helpers
) {
let { text, createBlock, list, multi, html, toggler, comment } = bdom;
let block2 = createBlock(\`<div>foo</div>\`);
let block3 = createBlock(\`<span>hey</span>\`);
return function template(ctx, node, key = \\"\\") {
const b2 = block2();
const b3 = block3();
return multi([b2, b3]);
}
}"
`;
exports[`simple templates, mostly static simple string 1`] = `
"function anonymous(app, bdom, helpers
) {
let { text, createBlock, list, multi, html, toggler, comment } = bdom;
return function template(ctx, node, key = \\"\\") {
return text(\`hello vdom\`);
}
}"
`;
exports[`simple templates, mostly static simple string in t tag 1`] = `
"function anonymous(app, bdom, helpers
) {
let { text, createBlock, list, multi, html, toggler, comment } = bdom;
return function template(ctx, node, key = \\"\\") {
return text(\`hello vdom\`);
}
}"
`;
exports[`simple templates, mostly static static text and dynamic text (no t tag) 1`] = `
"function anonymous(app, bdom, helpers
) {
let { text, createBlock, list, multi, html, toggler, comment } = bdom;
return function template(ctx, node, key = \\"\\") {
const b2 = text(\`hello \`);
const b3 = text(ctx['text']);
return multi([b2, b3]);
}
}"
`;
exports[`simple templates, mostly static static text and dynamic text 1`] = `
"function anonymous(app, bdom, helpers
) {
let { text, createBlock, list, multi, html, toggler, comment } = bdom;
return function template(ctx, node, key = \\"\\") {
const b2 = text(\`hello \`);
const b3 = text(ctx['text']);
return multi([b2, b3]);
}
}"
`;
exports[`simple templates, mostly static t-esc in dom node 1`] = `
"function anonymous(app, bdom, helpers
) {
let { text, createBlock, list, multi, html, toggler, comment } = bdom;
let block1 = createBlock(\`<div><block-text-0/></div>\`);
return function template(ctx, node, key = \\"\\") {
let txt1 = ctx['text'];
return block1([txt1]);
}
}"
`;
exports[`simple templates, mostly static t-esc in dom node, variations 1`] = `
"function anonymous(app, bdom, helpers
) {
let { text, createBlock, list, multi, html, toggler, comment } = bdom;
let block1 = createBlock(\`<div>hello <block-text-0/></div>\`);
return function template(ctx, node, key = \\"\\") {
let txt1 = ctx['text'];
return block1([txt1]);
}
}"
`;
exports[`simple templates, mostly static t-esc in dom node, variations 2`] = `
"function anonymous(app, bdom, helpers
) {
let { text, createBlock, list, multi, html, toggler, comment } = bdom;
let block1 = createBlock(\`<div>hello <block-text-0/> world</div>\`);
return function template(ctx, node, key = \\"\\") {
let txt1 = ctx['text'];
return block1([txt1]);
}
}"
`;
exports[`simple templates, mostly static template with multiple t tag with multiple content 1`] = `
"function anonymous(app, bdom, helpers
) {
let { text, createBlock, list, multi, html, toggler, comment } = bdom;
let block1 = createBlock(\`<div><block-text-0/><block-text-1/>Loading<block-text-2/></div>\`);
return function template(ctx, node, key = \\"\\") {
let txt1 = ctx['a'];
let txt2 = ctx['b'];
let txt3 = ctx['c'];
return block1([txt1, txt2, txt3]);
}
}"
`;
exports[`simple templates, mostly static template with t tag with multiple content 1`] = `
"function anonymous(app, bdom, helpers
) {
let { text, createBlock, list, multi, html, toggler, comment } = bdom;
let block1 = createBlock(\`<div>Loading<block-child-0/></div>\`);
return function template(ctx, node, key = \\"\\") {
let b2;
if (false) {
b2 = text(\`\`);
}
return block1([], [b2]);
}
}"
`;
exports[`simple templates, mostly static text node with backslash at top level 1`] = `
"function anonymous(app, bdom, helpers
) {
let { text, createBlock, list, multi, html, toggler, comment } = bdom;
return function template(ctx, node, key = \\"\\") {
return text(\`\\\\\\\\\`);
}
}"
`;
exports[`simple templates, mostly static text node with backtick at top-level 1`] = `
"function anonymous(app, bdom, helpers
) {
let { text, createBlock, list, multi, html, toggler, comment } = bdom;
return function template(ctx, node, key = \\"\\") {
return text(\`\\\\\`\`);
}
}"
`;
exports[`simple templates, mostly static text node with interpolation sigil at top level 1`] = `
"function anonymous(app, bdom, helpers
) {
let { text, createBlock, list, multi, html, toggler, comment } = bdom;
return function template(ctx, node, key = \\"\\") {
return text(\`\\\\\${very cool}\`);
}
}"
`;
exports[`simple templates, mostly static two t-escs next to each other 1`] = `
"function anonymous(app, bdom, helpers
) {
let { text, createBlock, list, multi, html, toggler, comment } = bdom;
return function template(ctx, node, key = \\"\\") {
const b2 = text(ctx['text1']);
const b3 = text(ctx['text2']);
return multi([b2, b3]);
}
}"
`;
exports[`simple templates, mostly static two t-escs next to each other 2`] = `
"function anonymous(app, bdom, helpers
) {
let { text, createBlock, list, multi, html, toggler, comment } = bdom;
return function template(ctx, node, key = \\"\\") {
const b2 = text(ctx['text1']);
const b3 = text(ctx['text2']);
return multi([b2, b3]);
}
}"
`;
exports[`simple templates, mostly static two t-escs next to each other, in a div 1`] = `
"function anonymous(app, bdom, helpers
) {
let { text, createBlock, list, multi, html, toggler, comment } = bdom;
let block1 = createBlock(\`<div><block-text-0/><block-text-1/></div>\`);
return function template(ctx, node, key = \\"\\") {
let txt1 = ctx['text1'];
let txt2 = ctx['text2'];
return block1([txt1, txt2]);
}
}"
`;