mirror of
https://github.com/angular/angular-cli.git
synced 2025-05-17 11:03:53 +08:00
refactor(@schematics/angular): remove unused TS AST utils
This commit is contained in:
parent
23113077d7
commit
08b263ca94
@ -231,18 +231,6 @@ export function insertAfterLastOccurrence(nodes: ts.Node[],
|
|||||||
return new InsertChange(file, lastItemPosition, toInsert);
|
return new InsertChange(file, lastItemPosition, toInsert);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
export function getContentOfKeyLiteral(_source: ts.SourceFile, node: ts.Node): string | null {
|
|
||||||
if (node.kind == ts.SyntaxKind.Identifier) {
|
|
||||||
return (node as ts.Identifier).text;
|
|
||||||
} else if (node.kind == ts.SyntaxKind.StringLiteral) {
|
|
||||||
return (node as ts.StringLiteral).text;
|
|
||||||
} else {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
function _angularImportsFromNode(node: ts.ImportDeclaration,
|
function _angularImportsFromNode(node: ts.ImportDeclaration,
|
||||||
_sourceFile: ts.SourceFile): {[name: string]: string} {
|
_sourceFile: ts.SourceFile): {[name: string]: string} {
|
||||||
const ms = node.moduleSpecifier;
|
const ms = node.moduleSpecifier;
|
||||||
@ -336,38 +324,6 @@ export function getDecoratorMetadata(source: ts.SourceFile, identifier: string,
|
|||||||
.map(expr => expr.arguments[0] as ts.ObjectLiteralExpression);
|
.map(expr => expr.arguments[0] as ts.ObjectLiteralExpression);
|
||||||
}
|
}
|
||||||
|
|
||||||
function findClassDeclarationParent(node: ts.Node): ts.ClassDeclaration|undefined {
|
|
||||||
if (ts.isClassDeclaration(node)) {
|
|
||||||
return node;
|
|
||||||
}
|
|
||||||
|
|
||||||
return node.parent && findClassDeclarationParent(node.parent);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Given a source file with @NgModule class(es), find the name of the first @NgModule class.
|
|
||||||
*
|
|
||||||
* @param source source file containing one or more @NgModule
|
|
||||||
* @returns the name of the first @NgModule, or `undefined` if none is found
|
|
||||||
*/
|
|
||||||
export function getFirstNgModuleName(source: ts.SourceFile): string|undefined {
|
|
||||||
// First, find the @NgModule decorators.
|
|
||||||
const ngModulesMetadata = getDecoratorMetadata(source, 'NgModule', '@angular/core');
|
|
||||||
if (ngModulesMetadata.length === 0) {
|
|
||||||
return undefined;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Then walk parent pointers up the AST, looking for the ClassDeclaration parent of the NgModule
|
|
||||||
// metadata.
|
|
||||||
const moduleClass = findClassDeclarationParent(ngModulesMetadata[0]);
|
|
||||||
if (!moduleClass || !moduleClass.name) {
|
|
||||||
return undefined;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Get the class name of the module ClassDeclaration.
|
|
||||||
return moduleClass.name.text;
|
|
||||||
}
|
|
||||||
|
|
||||||
export function getMetadataField(
|
export function getMetadataField(
|
||||||
node: ts.ObjectLiteralExpression,
|
node: ts.ObjectLiteralExpression,
|
||||||
metadataField: string,
|
metadataField: string,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user