import { isDecorator, Node, isIdentifier, Decorator } from 'typescript'; export interface DecoratorMap { [name: string]: Decorator; } function _getDecoratorName(aDecorator: Decorator) { const token = aDecorator.expression.getFirstToken(); if (isIdentifier(token)) { return token.text; } } function _getDecorators(aNode: Node): DecoratorMap { const result: DecoratorMap = {}; const decs = aNode.decorators; if (decs) { decs.forEach(dec => { if (isDecorator(dec)) { const key = _getDecoratorName(dec); if (key) { result[key] = dec; } } }); } return result; } export { _getDecoratorName as tsGetDecoratorName, _getDecorators as tsGetDecorators };