refactor(language-service): clean up and exports and consolidate types (#36533)
PR Close #36533
This commit is contained in:
@ -132,62 +132,3 @@ export class ExternalTemplate extends BaseTemplate {
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a property assignment from the assignment value, or `undefined` if there is no
|
||||
* assignment.
|
||||
*/
|
||||
export function getPropertyAssignmentFromValue(value: ts.Node): ts.PropertyAssignment|undefined {
|
||||
if (!value.parent || !ts.isPropertyAssignment(value.parent)) {
|
||||
return;
|
||||
}
|
||||
return value.parent;
|
||||
}
|
||||
|
||||
/**
|
||||
* Given a decorator property assignment, return the ClassDeclaration node that corresponds to the
|
||||
* directive class the property applies to.
|
||||
* If the property assignment is not on a class decorator, no declaration is returned.
|
||||
*
|
||||
* For example,
|
||||
*
|
||||
* @Component({
|
||||
* template: '<div></div>'
|
||||
* ^^^^^^^^^^^^^^^^^^^^^^^---- property assignment
|
||||
* })
|
||||
* class AppComponent {}
|
||||
* ^---- class declaration node
|
||||
*
|
||||
* @param propAsgn property assignment
|
||||
*/
|
||||
export function getClassDeclFromDecoratorProp(propAsgnNode: ts.PropertyAssignment):
|
||||
ts.ClassDeclaration|undefined {
|
||||
if (!propAsgnNode.parent || !ts.isObjectLiteralExpression(propAsgnNode.parent)) {
|
||||
return;
|
||||
}
|
||||
const objLitExprNode = propAsgnNode.parent;
|
||||
if (!objLitExprNode.parent || !ts.isCallExpression(objLitExprNode.parent)) {
|
||||
return;
|
||||
}
|
||||
const callExprNode = objLitExprNode.parent;
|
||||
if (!callExprNode.parent || !ts.isDecorator(callExprNode.parent)) {
|
||||
return;
|
||||
}
|
||||
const decorator = callExprNode.parent;
|
||||
if (!decorator.parent || !ts.isClassDeclaration(decorator.parent)) {
|
||||
return;
|
||||
}
|
||||
const classDeclNode = decorator.parent;
|
||||
return classDeclNode;
|
||||
}
|
||||
|
||||
/**
|
||||
* Determines if a property assignment is on a class decorator.
|
||||
* See `getClassDeclFromDecoratorProperty`, which gets the class the decorator is applied to, for
|
||||
* more details.
|
||||
*
|
||||
* @param prop property assignment
|
||||
*/
|
||||
export function isClassDecoratorProperty(propAsgn: ts.PropertyAssignment): boolean {
|
||||
return !!getClassDeclFromDecoratorProp(propAsgn);
|
||||
}
|
||||
|
Reference in New Issue
Block a user