From 9a6f27c34ce32af346e20f9cae8ebaacff89cd56 Mon Sep 17 00:00:00 2001 From: Alex Rickabaugh Date: Mon, 2 Jul 2018 14:23:46 -0700 Subject: [PATCH] fix(ivy): support zero-argument @NgModule() invocations (#24738) It's possible to declare an argument-less NgModule: @NgModule() export class Foo {} Update the @NgModule compiler to support this usage. PR Close #24738 --- .../compiler-cli/src/ngtsc/annotations/src/ng_module.ts | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/packages/compiler-cli/src/ngtsc/annotations/src/ng_module.ts b/packages/compiler-cli/src/ngtsc/annotations/src/ng_module.ts index 5a7df1c339..1a91a0e238 100644 --- a/packages/compiler-cli/src/ngtsc/annotations/src/ng_module.ts +++ b/packages/compiler-cli/src/ngtsc/annotations/src/ng_module.ts @@ -37,10 +37,13 @@ export class NgModuleDecoratorHandler implements DecoratorHandler { - if (decorator.args === null || decorator.args.length !== 1) { + if (decorator.args === null || decorator.args.length > 1) { throw new Error(`Incorrect number of arguments to @NgModule decorator`); } - const meta = decorator.args[0]; + + // @NgModule can be invoked without arguments. In case it is, pretend as if a blank object + // literal was specified. This simplifies the code below. + const meta = decorator.args.length === 1 ? decorator.args[0] : ts.createObjectLiteral([]); if (!ts.isObjectLiteralExpression(meta)) { throw new Error(`Decorator argument must be literal.`); }