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
This commit is contained in:
parent
cee393d0da
commit
f35e9158b2
|
@ -540,8 +540,7 @@ export class NgModuleDecoratorHandler implements
|
|||
}
|
||||
|
||||
// Verify that a `ts.Declaration` reference is a `ClassDeclaration` reference.
|
||||
private isClassDeclarationReference(ref: Reference<ts.Declaration>):
|
||||
ref is Reference<ClassDeclaration> {
|
||||
private isClassDeclarationReference(ref: Reference): ref is Reference<ClassDeclaration> {
|
||||
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<ts.Declaration> {
|
||||
return ref instanceof Reference &&
|
||||
(ts.isClassDeclaration(ref.node) || ts.isFunctionDeclaration(ref.node) ||
|
||||
ts.isVariableDeclaration(ref.node));
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue