mirror of
https://github.com/odoo/owl.git
synced 2025-10-06 19:59:41 +07:00
[FIX] compiler: allow t-if with empty content
This commit is contained in:
committed by
Aaron Bohy
parent
49c7585998
commit
2e176f135d
@@ -639,10 +639,7 @@ function parseTIf(node: Element, ctx: ParsingContext): AST | null {
|
||||
}
|
||||
const condition = node.getAttribute("t-if")!;
|
||||
node.removeAttribute("t-if");
|
||||
const content = parseNode(node, ctx);
|
||||
if (!content) {
|
||||
throw new Error("hmmm");
|
||||
}
|
||||
const content = parseNode(node, ctx) || { type: ASTType.Text, value: "" };
|
||||
|
||||
let nextElement = node.nextElementSibling;
|
||||
// t-elifs
|
||||
|
||||
@@ -384,6 +384,23 @@ exports[`t-if t-if in a t-if 1`] = `
|
||||
}"
|
||||
`;
|
||||
|
||||
exports[`t-if t-if with empty content 1`] = `
|
||||
"function anonymous(bdom, helpers
|
||||
) {
|
||||
let { text, createBlock, list, multi, html, toggler, component, comment } = bdom;
|
||||
let { withDefault, getTemplate, prepareList, withKey, zero, call, callSlot, capture, isBoundary, shallowEqual, setContextValue, toNumber, safeOutput } = helpers;
|
||||
|
||||
return function template(ctx, node, key = \\"\\") {
|
||||
let b2,b3;
|
||||
b2 = text(\`hello\`);
|
||||
if (ctx['condition']) {
|
||||
b3 = text(\`\`);
|
||||
}
|
||||
return multi([b2, b3]);
|
||||
}
|
||||
}"
|
||||
`;
|
||||
|
||||
exports[`t-if t-if/t-else with more content 1`] = `
|
||||
"function anonymous(bdom, helpers
|
||||
) {
|
||||
|
||||
@@ -395,6 +395,19 @@ describe("qweb parser", () => {
|
||||
});
|
||||
});
|
||||
|
||||
test("t-if with empty content", async () => {
|
||||
expect(parse(`<t t-if="condition"></t>`)).toEqual({
|
||||
type: ASTType.TIf,
|
||||
condition: "condition",
|
||||
content: {
|
||||
type: ASTType.Text,
|
||||
value: "",
|
||||
},
|
||||
tElif: null,
|
||||
tElse: null,
|
||||
});
|
||||
});
|
||||
|
||||
test("t-if (on dom node", async () => {
|
||||
expect(parse(`<div t-if="condition">hey</div>`)).toEqual({
|
||||
type: ASTType.TIf,
|
||||
|
||||
@@ -16,6 +16,12 @@ describe("t-if", () => {
|
||||
expect(renderToString(template, {})).toBe("<div></div>");
|
||||
});
|
||||
|
||||
test("t-if with empty content", () => {
|
||||
const template = `hello<t t-if="condition"/>`;
|
||||
expect(renderToString(template, { condition: true })).toBe("hello");
|
||||
expect(renderToString(template, { condition: false })).toBe("hello");
|
||||
});
|
||||
|
||||
test("boolean value condition missing", () => {
|
||||
const template = `<span><t t-if="condition">fail</t></span>`;
|
||||
expect(renderToString(template)).toBe("<span></span>");
|
||||
|
||||
Reference in New Issue
Block a user