import fs from 'fs' ; import path from 'path' ; export param { string } rootPath param { * } body param { { components : string [ ] , directives : string [ ] } } parseVnodeOptions param { Map < string , { templateUrl : string ; templateString : string ; classBody : any ; } > } componentMap export function classDecoratorCompiler ( rootPath , body , parseVnodeOptions , componentMap ) { if ( body . decorators ) { body . decorators . forEach ( ( decorator ) => { if ( decorator . expression && decorator . expression . callee && decorator . expression . callee . name === 'Component' ) { if ( decorator . expression . arguments ) { decorator . expression . arguments . forEach ( ( argument ) => { const selectorProperty = argument . properties . find ( ( property ) => property . key . name === 'selector' ) ; const templateProperty = argument . properties . find ( ( property ) => property . key . name === 'templateUrl' ) ; let selector ; if ( selectorProperty && selectorProperty . value && selectorProperty . value . value ) { selector = selectorProperty . value . value ; parseVnodeOptions . components . push ( selector ) ; } if ( templateProperty && templateProperty . value && templateProperty . value . value ) { let templatePath = templateProperty . value . value ; if ( rootPath ) { if ( path . isAbsolute ( templateProperty . value . value ) ) templatePath = `${ rootPath }${ templateProperty . value . value }` ; else templatePath = path . resolve ( rootPath , templateProperty . value . value ) ; } const templateString = fs . readFileSync ( templatePath ) . toString ( ) ; componentMap . set ( selector , { templateUrl : templatePath , templateString , classBody : body , } ) ; } } ) ; } } if ( decorator . expression && decorator . expression . callee && decorator . expression . callee . name === 'Directive' ) { if ( decorator . expression . arguments ) { decorator . expression . arguments . forEach ( ( argument ) => { argument . properties . forEach ( ( property ) => { if ( property . key . name === 'selector' ) parseVnodeOptions . directives . push ( property . value . value ) ; } ) ; } ) ; } } } ) ; } }