diff --git a/src/qweb_extensions.ts b/src/qweb_extensions.ts index fbb30303..37c2f503 100644 --- a/src/qweb_extensions.ts +++ b/src/qweb_extensions.ts @@ -235,9 +235,11 @@ QWeb.addDirective({ `def${defID} = w${widgetID}._updateProps(props${widgetID}, extra.forceUpdate, extra.patchQueue);` ); ctx.addElse(); - ctx.addLine( - `w${widgetID} = new context.widgets['${value}'](owner, props${widgetID});` - ); + ctx.addLine(`let W${widgetID} = context.widgets['${value}'];`); + + // maybe only do this in dev mode... + ctx.addLine(`if (!W${widgetID}) {throw new Error(\`Cannot find the definition of widget "${value}"\`)}`); + ctx.addLine(`w${widgetID} = new W${widgetID}(owner, props${widgetID});`); ctx.addLine( `context.__owl__.cmap[${templateID}] = w${widgetID}.__owl__.id;` ); diff --git a/tests/__snapshots__/component.test.ts.snap b/tests/__snapshots__/component.test.ts.snap index 31005986..66c6ba27 100644 --- a/tests/__snapshots__/component.test.ts.snap +++ b/tests/__snapshots__/component.test.ts.snap @@ -31,7 +31,9 @@ exports[`class and style attributes with t-widget dynamic t-att-style is properl if (w4) { def3 = w4._updateProps(props4, extra.forceUpdate, extra.patchQueue); } else { - w4 = new context.widgets['child'](owner, props4); + let W4 = context.widgets['child']; + if (!W4) {throw new Error(\`Cannot find the definition of widget \\"child\\"\`)} + w4 = new W4(owner, props4); context.__owl__.cmap[4] = w4.__owl__.id; def3 = w4._prepare(); } @@ -78,7 +80,9 @@ exports[`class and style attributes with t-widget t-att-class is properly added/ if (w4) { def3 = w4._updateProps(props4, extra.forceUpdate, extra.patchQueue); } else { - w4 = new context.widgets['child'](owner, props4); + let W4 = context.widgets['child']; + if (!W4) {throw new Error(\`Cannot find the definition of widget \\"child\\"\`)} + w4 = new W4(owner, props4); context.__owl__.cmap[4] = w4.__owl__.id; def3 = w4._prepare(); } @@ -143,7 +147,9 @@ exports[`composition sub widgets with some state rendered in a loop 1`] = ` if (w7) { def6 = w7._updateProps(props7, extra.forceUpdate, extra.patchQueue); } else { - w7 = new context.widgets['ChildWidget'](owner, props7); + let W7 = context.widgets['ChildWidget']; + if (!W7) {throw new Error(\`Cannot find the definition of widget \\"ChildWidget\\"\`)} + w7 = new W7(owner, props7); context.__owl__.cmap[key8] = w7.__owl__.id; def6 = w7._prepare(); } @@ -191,7 +197,9 @@ exports[`random stuff/miscellaneous snapshotting compiled code 1`] = ` if (w4) { def3 = w4._updateProps(props4, extra.forceUpdate, extra.patchQueue); } else { - w4 = new context.widgets['child'](owner, props4); + let W4 = context.widgets['child']; + if (!W4) {throw new Error(\`Cannot find the definition of widget \\"child\\"\`)} + w4 = new W4(owner, props4); context.__owl__.cmap[key5] = w4.__owl__.id; def3 = w4._prepare(); } @@ -237,7 +245,9 @@ exports[`random stuff/miscellaneous t-props should not be undefined (snapshottin if (w4) { def3 = w4._updateProps(props4, extra.forceUpdate, extra.patchQueue); } else { - w4 = new context.widgets['child'](owner, props4); + let W4 = context.widgets['child']; + if (!W4) {throw new Error(\`Cannot find the definition of widget \\"child\\"\`)} + w4 = new W4(owner, props4); context.__owl__.cmap[4] = w4.__owl__.id; def3 = w4._prepare(); } diff --git a/tests/component.test.ts b/tests/component.test.ts index cabb4713..fcb1c556 100644 --- a/tests/component.test.ts +++ b/tests/component.test.ts @@ -852,6 +852,25 @@ describe("composition", () => { expect(children(widget)[0].__owl__.parent).toBe(widget); }); + test("throw a nice error if it cannot find widget", async () => { + expect.assertions(1); + env.qweb.addTemplate( + "Parent", + `