mirror of
https://github.com/odoo/owl.git
synced 2025-10-06 19:59:41 +07:00
[IMP] qweb: throw error when t-component is not used with a 't' tag
This commit is contained in:
committed by
Aaron Bohy
parent
52fa81c510
commit
d569ea1c28
@@ -645,6 +645,10 @@ function parseComponent(node: Element, ctx: ParsingContext): AST | null {
|
|||||||
const firstLetter = name[0];
|
const firstLetter = name[0];
|
||||||
let isDynamic = node.hasAttribute("t-component");
|
let isDynamic = node.hasAttribute("t-component");
|
||||||
|
|
||||||
|
if (isDynamic && name !== "t") {
|
||||||
|
throw new Error(`Directive 't-component' can only be used on <t> nodes (used on a <${name}>)`);
|
||||||
|
}
|
||||||
|
|
||||||
if (!(firstLetter === firstLetter.toUpperCase() || isDynamic)) {
|
if (!(firstLetter === firstLetter.toUpperCase() || isDynamic)) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -212,22 +212,6 @@ exports[`t-component t-component not on a <t> node 1`] = `
|
|||||||
}"
|
}"
|
||||||
`;
|
`;
|
||||||
|
|
||||||
exports[`t-component t-component not on a <t> node 2`] = `
|
|
||||||
"function anonymous(bdom, helpers
|
|
||||||
) {
|
|
||||||
let { text, createBlock, list, multi, html, toggler, component } = bdom;
|
|
||||||
let { withDefault, getTemplate, prepareList, withKey, zero, call, callSlot, capture, shallowEqual } = helpers;
|
|
||||||
|
|
||||||
let block1 = createBlock(\`<div><block-child-0/></div>\`);
|
|
||||||
|
|
||||||
return function template(ctx, node, key = \\"\\") {
|
|
||||||
let Comp2 = ctx['Child'];
|
|
||||||
let b2 = toggler(Comp2, component(Comp2, {}, key + \`__1\`, node, ctx));
|
|
||||||
return block1([], [b2]);
|
|
||||||
}
|
|
||||||
}"
|
|
||||||
`;
|
|
||||||
|
|
||||||
exports[`t-component t-component works in simple case 1`] = `
|
exports[`t-component t-component works in simple case 1`] = `
|
||||||
"function anonymous(bdom, helpers
|
"function anonymous(bdom, helpers
|
||||||
) {
|
) {
|
||||||
|
|||||||
@@ -191,7 +191,7 @@ describe("t-component", () => {
|
|||||||
expect(fixture.innerHTML).toBe("<div><div>1<button>Inc</button></div></div>");
|
expect(fixture.innerHTML).toBe("<div><div>1<button>Inc</button></div></div>");
|
||||||
});
|
});
|
||||||
|
|
||||||
test.skip("t-component not on a <t> node", async () => {
|
test("t-component not on a <t> node", async () => {
|
||||||
class Child extends Component {
|
class Child extends Component {
|
||||||
static template = xml`<span>1</span>`;
|
static template = xml`<span>1</span>`;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user