diff --git a/packages/compiler-cli/ngcc/test/analysis/module_with_providers_analyzer_spec.ts b/packages/compiler-cli/ngcc/test/analysis/module_with_providers_analyzer_spec.ts index 8dbbf5007b..c3735c4184 100644 --- a/packages/compiler-cli/ngcc/test/analysis/module_with_providers_analyzer_spec.ts +++ b/packages/compiler-cli/ngcc/test/analysis/module_with_providers_analyzer_spec.ts @@ -10,8 +10,8 @@ import * as ts from 'typescript'; import {absoluteFrom, AbsoluteFsPath, getSourceFileOrError} from '../../../src/ngtsc/file_system'; import {runInEachFileSystem, TestFile} from '../../../src/ngtsc/file_system/testing'; import {MockLogger} from '../../../src/ngtsc/logging/testing'; -import {DeclarationNode, isNamedClassDeclaration, isNamedVariableDeclaration} from '../../../src/ngtsc/reflection'; -import {getDeclaration} from '../../../src/ngtsc/testing'; +import {DeclarationNode} from '../../../src/ngtsc/reflection'; +import {getDeclaration, isNamedDeclaration} from '../../../src/ngtsc/testing'; import {loadTestFiles} from '../../../test/helpers'; import {ModuleWithProvidersAnalyses, ModuleWithProvidersAnalyzer} from '../../src/analysis/module_with_providers_analyzer'; import {NgccReferencesRegistry} from '../../src/analysis/ngcc_references_registry'; @@ -661,9 +661,7 @@ runInEachFileSystem(() => { } function getName(node: DeclarationNode|null): string { - return node && (isNamedVariableDeclaration(node) || isNamedClassDeclaration(node)) ? - `${node.name.text}.` : - ''; + return node && isNamedDeclaration(node) ? `${node.name.text}.` : ''; } }); }); diff --git a/packages/compiler-cli/src/ngtsc/testing/index.ts b/packages/compiler-cli/src/ngtsc/testing/index.ts index 354d8a3876..052bfc8773 100644 --- a/packages/compiler-cli/src/ngtsc/testing/index.ts +++ b/packages/compiler-cli/src/ngtsc/testing/index.ts @@ -5,4 +5,4 @@ * Use of this source code is governed by an MIT-style license that can be * found in the LICENSE file at https://angular.io/license */ -export {expectCompleteReuse, getDeclaration, makeProgram} from './src/utils'; +export {expectCompleteReuse, getDeclaration, isNamedDeclaration, makeProgram} from './src/utils'; diff --git a/packages/compiler-cli/src/ngtsc/testing/src/utils.ts b/packages/compiler-cli/src/ngtsc/testing/src/utils.ts index cfaa5cba85..7fe09b6686 100644 --- a/packages/compiler-cli/src/ngtsc/testing/src/utils.ts +++ b/packages/compiler-cli/src/ngtsc/testing/src/utils.ts @@ -93,9 +93,7 @@ export function walkForDeclarations(name: string, rootNode: ts.Node): Declaratio chosenDecls.push(...walkForDeclarations(name, node)); } }); - } else if ( - ts.isClassDeclaration(node) || ts.isFunctionDeclaration(node) || - ts.isInterfaceDeclaration(node) || ts.isClassExpression(node)) { + } else if (isNamedDeclaration(node)) { if (node.name !== undefined && node.name.text === name) { chosenDecls.push(node); } @@ -111,6 +109,11 @@ export function walkForDeclarations(name: string, rootNode: ts.Node): Declaratio return chosenDecls; } +export function isNamedDeclaration(node: ts.Node): node is ts.Declaration&{name: ts.Identifier} { + const namedNode = node as {name?: ts.Identifier}; + return namedNode.name !== undefined && ts.isIdentifier(namedNode.name); +} + const COMPLETE_REUSE_FAILURE_MESSAGE = 'The original program was not reused completely, even though no changes should have been made to its structure';