refactor(core): move schematic base classes logic into shared utils (#35339)
Moves the `findBaseClassDeclarations` method into the shared schematic utilities. This method will be useful for future migrations, and for planned changes to the `undecorated-classes-with-decorated-fields` migration. PR Close #35339
This commit is contained in:

committed by
Kara Erickson

parent
c3ce1903b6
commit
eee5eeae76
@ -1,30 +0,0 @@
|
||||
/**
|
||||
* @license
|
||||
* Copyright Google Inc. All Rights Reserved.
|
||||
*
|
||||
* 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
|
||||
*/
|
||||
|
||||
import * as ts from 'typescript';
|
||||
import {getBaseTypeIdentifiers} from '../../utils/typescript/class_declaration';
|
||||
|
||||
/** Gets all base class declarations of the specified class declaration. */
|
||||
export function findBaseClassDeclarations(node: ts.ClassDeclaration, typeChecker: ts.TypeChecker) {
|
||||
const result: {identifier: ts.Identifier, node: ts.ClassDeclaration}[] = [];
|
||||
let currentClass = node;
|
||||
|
||||
while (currentClass) {
|
||||
const baseTypes = getBaseTypeIdentifiers(currentClass);
|
||||
if (!baseTypes || baseTypes.length !== 1) {
|
||||
break;
|
||||
}
|
||||
const symbol = typeChecker.getTypeAtLocation(baseTypes[0]).getSymbol();
|
||||
if (!symbol || !ts.isClassDeclaration(symbol.valueDeclaration)) {
|
||||
break;
|
||||
}
|
||||
result.push({identifier: baseTypes[0], node: symbol.valueDeclaration});
|
||||
currentClass = symbol.valueDeclaration;
|
||||
}
|
||||
return result;
|
||||
}
|
@ -13,11 +13,11 @@ import * as ts from 'typescript';
|
||||
|
||||
import {getAngularDecorators} from '../../utils/ng_decorators';
|
||||
import {hasExplicitConstructor} from '../../utils/typescript/class_declaration';
|
||||
import {findBaseClassDeclarations} from '../../utils/typescript/find_base_classes';
|
||||
import {getImportOfIdentifier} from '../../utils/typescript/imports';
|
||||
|
||||
import {UnexpectedMetadataValueError, convertDirectiveMetadataToExpression} from './decorator_rewrite/convert_directive_metadata';
|
||||
import {DecoratorRewriter} from './decorator_rewrite/decorator_rewriter';
|
||||
import {findBaseClassDeclarations} from './find_base_classes';
|
||||
import {ImportManager} from './import_manager';
|
||||
import {hasDirectiveDecorator, hasInjectableDecorator} from './ng_declaration_collector';
|
||||
import {UpdateRecorder} from './update_recorder';
|
||||
|
Reference in New Issue
Block a user