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
This commit is contained in:
Alex Rickabaugh 2018-07-02 14:23:46 -07:00 committed by Matias Niemelä
parent d723a69b31
commit 9a6f27c34c
1 changed files with 5 additions and 2 deletions

View File

@ -37,10 +37,13 @@ export class NgModuleDecoratorHandler implements DecoratorHandler<NgModuleAnalys
} }
analyze(node: ts.ClassDeclaration, decorator: Decorator): AnalysisOutput<NgModuleAnalysis> { analyze(node: ts.ClassDeclaration, decorator: Decorator): AnalysisOutput<NgModuleAnalysis> {
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`); 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)) { if (!ts.isObjectLiteralExpression(meta)) {
throw new Error(`Decorator argument must be literal.`); throw new Error(`Decorator argument must be literal.`);
} }