From ee64de8b3f307a09313bca71730b5ecbe775b68e Mon Sep 17 00:00:00 2001 From: Mathieu Duckerts-Antoine Date: Tue, 19 Oct 2021 16:01:36 +0200 Subject: [PATCH] [IMP] qweb: throw error when t-component is not used with a 't' tag --- src/qweb/parser.ts | 4 ++++ .../__snapshots__/t_component.test.ts.snap | 16 ---------------- tests/components/t_component.test.ts | 2 +- 3 files changed, 5 insertions(+), 17 deletions(-) diff --git a/src/qweb/parser.ts b/src/qweb/parser.ts index e563d1b6..bd5b3fcb 100644 --- a/src/qweb/parser.ts +++ b/src/qweb/parser.ts @@ -645,6 +645,10 @@ function parseComponent(node: Element, ctx: ParsingContext): AST | null { const firstLetter = name[0]; let isDynamic = node.hasAttribute("t-component"); + if (isDynamic && name !== "t") { + throw new Error(`Directive 't-component' can only be used on nodes (used on a <${name}>)`); + } + if (!(firstLetter === firstLetter.toUpperCase() || isDynamic)) { return null; } diff --git a/tests/components/__snapshots__/t_component.test.ts.snap b/tests/components/__snapshots__/t_component.test.ts.snap index f2ee0124..bd999847 100644 --- a/tests/components/__snapshots__/t_component.test.ts.snap +++ b/tests/components/__snapshots__/t_component.test.ts.snap @@ -212,22 +212,6 @@ exports[`t-component t-component not on a node 1`] = ` }" `; -exports[`t-component t-component not on a 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(\`
\`); - - 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`] = ` "function anonymous(bdom, helpers ) { diff --git a/tests/components/t_component.test.ts b/tests/components/t_component.test.ts index e6e364e4..2fdacf8e 100644 --- a/tests/components/t_component.test.ts +++ b/tests/components/t_component.test.ts @@ -191,7 +191,7 @@ describe("t-component", () => { expect(fixture.innerHTML).toBe("
1
"); }); - test.skip("t-component not on a node", async () => { + test("t-component not on a node", async () => { class Child extends Component { static template = xml`1`; }