import * as host from '../utils/host' ; import * as injector from '../utils/injector' ; import * as input from '../utils/input' ; import * as output from '../utils/output' ; function parseSelector ( selector ) { const regex = [ { key : 'A' , value : /^\[([a-zA-Z]+)\]$/ } , { key : 'C' , value : /^\.([a-zA-Z]+)$/ } ] ; for ( let i = 0 ; i < regex . length ; i ++ ) { const result = selector . match ( regex [ i ] . value ) ; if ( result !== null ) { return { restrict : regex [ i ] . key , name : result [ 1 ] } ; } } ; throw new Error ( `Selector ${ selector } could not be parsed` ) ; } export function bootstrap ( ngModule , target ) { const annotations = target . __annotations__ ; const directive = annotations . directive ; const selector = parseSelector ( directive . selector ) ; const hostBindings = host . parse ( directive . host || { } ) ; injector . inject ( ngModule , target ) ; ngModule . controller ( target . name , target ) . directive ( selector . name , [ '$rootScope' , ( $rootScope ) => { const declaration = { restrict : selector . restrict , scope : { } , bindToController : { } , controller : target . name , controllerAs : '$ctrl' , link : ( scope , el ) => host . bind ( scope , el , hostBindings ) } ; input . bind ( target , declaration ) ; output . bind ( $rootScope , target , declaration ) ; return declaration ; } ] ) ; }