mirror of
https://github.com/angular/angular.git
synced 2026-09-14 13:54:52 +08:00
fc97a41f07
This helper accepts a class, and returns the primary Angular Decorator associated with that trait (e.g. the Component, Pipe, Directive, or NgModule decorator). This will be useful for the language service import project, which needs to edit import arrays inside the decorator. PR Close #47180
19 lines
652 B
TypeScript
19 lines
652 B
TypeScript
/**
|
|
* @license
|
|
* Copyright Google LLC 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 {ClassDeclaration, isNamedClassDeclaration} from '@angular/compiler-cli/src/ngtsc/reflection';
|
|
import ts from 'typescript';
|
|
|
|
export function getClass(sf: ts.SourceFile, name: string): ClassDeclaration<ts.ClassDeclaration> {
|
|
for (const stmt of sf.statements) {
|
|
if (isNamedClassDeclaration(stmt) && stmt.name.text === name) {
|
|
return stmt;
|
|
}
|
|
}
|
|
throw new Error(`Class ${name} not found in file: ${sf.fileName}: ${sf.text}`);
|
|
}
|