import { SyntaxKind , ClassDeclaration , SourceFile , PropertyAssignment , StringLiteral , Identifier , ArrayLiteralExpression } from 'ts-simple-ast' ; import { AngularExternalResourcesAnalyzer } from '../external-resources/angular-external-resources.analyzer' ; import { AngularExternalStyles , AngularExternalResource } from '../external-resources/angular-external-resources.interfaces' ; /**
 * Angular External Styles Analyzer
 */ export class AngularExternalStylesAnalyzer extends AngularExternalResourcesAnalyzer { param sourceFile returns public static getExternalStyles ( sourceFile ) { return sourceFile . getClasses ( ) . reduce ( ( externalStylesAssignment , classDeclaration ) : Array < PropertyAssignment > => { try { return [ ... externalStylesAssignment , this . getComponentDecoratorPropertyOrThrow ( classDeclaration , 'styleUrls' ) ] ; } catch { return externalStylesAssignment ; } } , [ ] ) . map ( ( externalStylesAssignment ) : AngularExternalStyles => { const externalStylesKey = this . getExternalStylesAssignmentKeyOrThrow ( externalStylesAssignment ) ; const externalStyleValues = this . getExternalStylesAssignmentValuesOrThrow ( externalStylesAssignment ) ; const externalStyles = externalStyleValues . map ( ( externalStyleValue ) : AngularExternalResource => { const externalStylePath = this . getExternalResourcePath ( externalStyleValue ) ; const resolvedExternalStylePath = this . resolveExternalResourcePath ( externalStylePath , sourceFile ) ; return { node : externalStyleValue , path : resolvedExternalStylePath } ; } ) ; return { node : externalStylesKey , styles : externalStyles } ; } ) ; } param externalStylesAssignment returns private static getExternalStylesAssignmentKeyOrThrow ( externalStylesAssignment ) { return < Identifier > externalStylesAssignment . getChildrenOfKind ( SyntaxKind . Identifier ) [ 0 ] || ( ( ) => { throw new Error ( 'External template does not have a key.' ) ; } ) ( ) ; } param externalStylesAssignment returns private static getExternalStylesAssignmentValuesOrThrow ( externalStylesAssignment ) { const externalStylesAssignmentValue = < ArrayLiteralExpression > externalStylesAssignment . getChildrenOfKind ( SyntaxKind . ArrayLiteralExpression ) [ 0 ] || ( ( ) => { throw new Error ( 'External template doesn ot have a vlaue.' ) ; } ) ( ) ; const externalStylesAssignmentValues = < Array < StringLiteral > > externalStylesAssignmentValue . getElements ( ) ; return externalStylesAssignmentValues ; } }