From f35e9158b2b18620cfe4ba4abbd4376543b78d1d Mon Sep 17 00:00:00 2001 From: Pete Bacon Darwin Date: Sun, 27 Sep 2020 10:50:51 +0100 Subject: [PATCH] refactor(compiler-cli): remove unnecessary constraint on `isDeclarationReference()` (#38959) There is no need to check that the `ref.node` is of any particular type because immediately after this check the entry is tested to see if it passes `isClassDeclarationReference()`. The only difference is that the error that is reported is slightly different in the case that it is a `ref` but not one of the TS node types. Previously: ``` `Value at position ${idx} in the NgModule.${arrayName} of ${ className} is not a reference` ``` now ``` `Value at position ${idx} in the NgModule.${arrayName} of ${ className} is not a class` ``` Arguably the previous message was wrong, since this entry IS a reference but is not a class. PR Close #38959 --- .../src/ngtsc/annotations/src/ng_module.ts | 11 ++--------- 1 file changed, 2 insertions(+), 9 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 3cc6ece9f5..d57b6e6ea4 100644 --- a/packages/compiler-cli/src/ngtsc/annotations/src/ng_module.ts +++ b/packages/compiler-cli/src/ngtsc/annotations/src/ng_module.ts @@ -540,8 +540,7 @@ export class NgModuleDecoratorHandler implements } // Verify that a `ts.Declaration` reference is a `ClassDeclaration` reference. - private isClassDeclarationReference(ref: Reference): - ref is Reference { + private isClassDeclarationReference(ref: Reference): ref is Reference { return this.reflector.isClass(ref.node); } @@ -568,7 +567,7 @@ export class NgModuleDecoratorHandler implements if (Array.isArray(entry)) { // Recurse into nested arrays. refList.push(...this.resolveTypeList(expr, entry, className, arrayName)); - } else if (isDeclarationReference(entry)) { + } else if (entry instanceof Reference) { if (!this.isClassDeclarationReference(entry)) { throw createValueHasWrongTypeError( entry.node, entry, @@ -593,9 +592,3 @@ function isNgModule(node: ClassDeclaration, compilation: ScopeData): boolean { return !compilation.directives.some(directive => directive.ref.node === node) && !compilation.pipes.some(pipe => pipe.ref.node === node); } - -function isDeclarationReference(ref: any): ref is Reference { - return ref instanceof Reference && - (ts.isClassDeclaration(ref.node) || ts.isFunctionDeclaration(ref.node) || - ts.isVariableDeclaration(ref.node)); -}