UNPKG

criticizer

Version:

Linting for Angular applications, following angular.io/styleguide.

30 lines (25 loc) 1.18 kB
import * as ts from 'typescript'; import {Maybe} from './function'; import { decoratorArgument, getInitializer, isProperty, isArrayLiteralExpression, WithStringInitializer, getStringInitializerFromProperty } from './astQuery'; export function getInlineStyle(dec: ts.Decorator): Maybe<ts.ArrayLiteralExpression> { return decoratorArgument(dec) .bind((expr: ts.ObjectLiteralExpression) => { const property = expr.properties.find(p => isProperty('styles', p)); return getInitializer(property) .fmap(expr => isArrayLiteralExpression(expr) ? expr as ts.ArrayLiteralExpression : undefined); }); } export function getTemplateUrl(dec: ts.Decorator): Maybe<WithStringInitializer> { return decoratorArgument(dec) .bind((expr: ts.ObjectLiteralExpression) => getStringInitializerFromProperty('templateUrl', expr.properties)); } export function getTemplate(dec: ts.Decorator): Maybe<WithStringInitializer> { return decoratorArgument(dec) .bind((expr: ts.ObjectLiteralExpression) => getStringInitializerFromProperty('template', expr.properties)); }