test(ngcc): use isNamedDeclaration()
helper to simplify tests (#38959)
Previously these tests were checking multiple specific expression types. The new helper function is more general and will also support `PropertyAccessExpression` nodes for `InlineDeclaration` types. PR Close #38959
This commit is contained in:

committed by
atscott

parent
0accd1e68d
commit
47eab61cad
@ -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';
|
||||
|
@ -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';
|
||||
|
||||
|
Reference in New Issue
Block a user