2016-04-28 20:50:03 -04:00
import {
2016-05-26 18:07:51 -04:00
AnimationMetadata ,
AnimationEntryMetadata ,
AnimationStateMetadata ,
AnimationStateDeclarationMetadata ,
AnimationStateTransitionMetadata ,
AnimationStyleMetadata ,
AnimationKeyframesSequenceMetadata ,
AnimationAnimateMetadata ,
AnimationWithStepsMetadata ,
AnimationGroupMetadata ,
2016-04-28 20:50:03 -04:00
AttributeMetadata ,
OptionalMetadata ,
ComponentMetadata ,
SelfMetadata ,
HostMetadata ,
SkipSelfMetadata ,
Provider ,
2016-05-02 01:50:37 -04:00
PLATFORM_DIRECTIVES ,
PLATFORM_PIPES ,
Injectable ,
Inject ,
Optional ,
2016-04-28 20:50:03 -04:00
ViewMetadata ,
QueryMetadata ,
resolveForwardRef ,
InjectMetadata ,
ViewQueryMetadata
} from '@angular/core' ;
2016-05-25 18:00:05 -04:00
import { LIFECYCLE_HOOKS_VALUES , ReflectorReader , reflector } from '../core_private' ;
2016-04-12 12:40:37 -04:00
import {
Type ,
isBlank ,
isPresent ,
isArray ,
stringify ,
2016-01-06 17:13:44 -05:00
isString ,
2016-04-28 20:50:03 -04:00
isStringMap
} from '../src/facade/lang' ;
import { StringMapWrapper } from '../src/facade/collection' ;
import { BaseException } from '../src/facade/exceptions' ;
2016-01-06 17:13:44 -05:00
import * as cpl from './compile_metadata' ;
import { DirectiveResolver } from './directive_resolver' ;
import { PipeResolver } from './pipe_resolver' ;
import { ViewResolver } from './view_resolver' ;
import { hasLifecycleHook } from './directive_lifecycle_reflector' ;
2016-04-30 19:13:03 -04:00
import { MODULE_SUFFIX , sanitizeIdentifier , ValueTransformer , visitValue } from './util' ;
2016-03-09 17:55:27 -05:00
import { assertArrayOfStrings } from './assertions' ;
2016-04-28 20:50:03 -04:00
import { getUrlScheme } from './url_resolver' ;
import { createProvider , isProviderLiteral } from "../core_private" ;
2015-09-14 18:59:09 -04:00
@Injectable ( )
2016-02-18 13:53:21 -05:00
export class CompileMetadataResolver {
2015-12-02 13:35:51 -05:00
private _directiveCache = new Map < Type , cpl.CompileDirectiveMetadata > ( ) ;
private _pipeCache = new Map < Type , cpl.CompilePipeMetadata > ( ) ;
2016-03-29 20:15:07 -04:00
private _anonymousTypes = new Map < Object , number > ( ) ;
private _anonymousTypeIndex = 0 ;
2016-02-18 13:53:21 -05:00
private _reflector : ReflectorReader ;
2015-09-14 18:59:09 -04:00
2016-04-12 12:40:37 -04:00
constructor ( private _directiveResolver : DirectiveResolver , private _pipeResolver : PipeResolver ,
private _viewResolver : ViewResolver ,
@Optional ( ) @Inject ( PLATFORM_DIRECTIVES ) private _platformDirectives : Type [ ] ,
2016-02-18 13:53:21 -05:00
@Optional ( ) @Inject ( PLATFORM_PIPES ) private _platformPipes : Type [ ] ,
_reflector? : ReflectorReader ) {
if ( isPresent ( _reflector ) ) {
this . _reflector = _reflector ;
} else {
this . _reflector = reflector ;
}
}
2015-09-14 18:59:09 -04:00
2016-04-20 21:10:19 -04:00
private sanitizeTokenName ( token : any ) : string {
let identifier = stringify ( token ) ;
if ( identifier . indexOf ( '(' ) >= 0 ) {
// case: anonymous functions!
let found = this . _anonymousTypes . get ( token ) ;
if ( isBlank ( found ) ) {
this . _anonymousTypes . set ( token , this . _anonymousTypeIndex ++ ) ;
found = this . _anonymousTypes . get ( token ) ;
}
identifier = ` anonymous_token_ ${ found } _ ` ;
2016-03-29 20:15:07 -04:00
}
2016-04-20 21:10:19 -04:00
return sanitizeIdentifier ( identifier ) ;
2016-03-29 20:15:07 -04:00
}
2016-05-26 18:07:51 -04:00
getAnimationEntryMetadata ( entry : AnimationEntryMetadata ) : cpl . CompileAnimationEntryMetadata {
2016-05-25 15:46:22 -04:00
var defs = entry . definitions . map ( def = > this . getAnimationStateMetadata ( def ) ) ;
return new cpl . CompileAnimationEntryMetadata ( entry . name , defs ) ;
}
2016-05-26 18:07:51 -04:00
getAnimationStateMetadata ( value : AnimationStateMetadata ) : cpl . CompileAnimationStateMetadata {
if ( value instanceof AnimationStateDeclarationMetadata ) {
2016-05-25 15:46:22 -04:00
var styles = this . getAnimationStyleMetadata ( value . styles ) ;
return new cpl . CompileAnimationStateDeclarationMetadata ( value . stateNameExpr , styles ) ;
2016-05-26 18:07:51 -04:00
} else if ( value instanceof AnimationStateTransitionMetadata ) {
2016-05-26 12:22:44 -04:00
return new cpl . CompileAnimationStateTransitionMetadata ( value . stateChangeExpr , this . getAnimationMetadata ( value . steps ) ) ;
2016-05-25 15:46:22 -04:00
}
return null ;
}
2016-05-26 18:07:51 -04:00
getAnimationStyleMetadata ( value : AnimationStyleMetadata ) : cpl . CompileAnimationStyleMetadata {
2016-05-25 15:46:22 -04:00
return new cpl . CompileAnimationStyleMetadata ( value . offset , value . styles ) ;
}
2016-05-26 18:07:51 -04:00
getAnimationMetadata ( value : AnimationMetadata ) : cpl . CompileAnimationMetadata {
if ( value instanceof AnimationStyleMetadata ) {
2016-05-25 15:46:22 -04:00
return this . getAnimationStyleMetadata ( value ) ;
2016-05-26 18:07:51 -04:00
} else if ( value instanceof AnimationKeyframesSequenceMetadata ) {
2016-05-25 15:46:22 -04:00
return new cpl . CompileAnimationKeyframesSequenceMetadata ( value . steps . map ( entry = > this . getAnimationStyleMetadata ( entry ) ) ) ;
2016-05-26 18:07:51 -04:00
} else if ( value instanceof AnimationAnimateMetadata ) {
2016-05-25 15:46:22 -04:00
let animateData = < cpl.CompileAnimationStyleMetadata | cpl.CompileAnimationKeyframesSequenceMetadata > this . getAnimationMetadata ( value . styles ) ;
return new cpl . CompileAnimationAnimateMetadata ( value . timings , animateData ) ;
2016-05-26 18:07:51 -04:00
} else if ( value instanceof AnimationWithStepsMetadata ) {
2016-05-25 15:46:22 -04:00
var steps = value . steps . map ( step = > this . getAnimationMetadata ( step ) ) ;
2016-05-26 18:07:51 -04:00
if ( value instanceof AnimationGroupMetadata ) {
2016-05-25 15:46:22 -04:00
return new cpl . CompileAnimationGroupMetadata ( steps ) ;
} else {
return new cpl . CompileAnimationSequenceMetadata ( steps ) ;
}
}
return null ;
}
2015-12-02 13:35:51 -05:00
getDirectiveMetadata ( directiveType : Type ) : cpl . CompileDirectiveMetadata {
var meta = this . _directiveCache . get ( directiveType ) ;
2015-09-14 18:59:09 -04:00
if ( isBlank ( meta ) ) {
2015-10-23 18:55:48 -04:00
var dirMeta = this . _directiveResolver . resolve ( directiveType ) ;
2016-06-08 18:45:15 -04:00
var templateMeta : any /** TODO #9100 */ = null ;
var changeDetectionStrategy : any /** TODO #9100 */ = null ;
var viewProviders : any [ ] /** TODO #9100 */ = [ ] ;
2016-05-02 19:45:43 -04:00
var module Url = staticTypeModuleUrl ( directiveType ) ;
2016-04-28 20:50:03 -04:00
if ( dirMeta instanceof ComponentMetadata ) {
2016-03-09 17:55:27 -05:00
assertArrayOfStrings ( 'styles' , dirMeta . styles ) ;
2016-04-28 20:50:03 -04:00
var cmpMeta = < ComponentMetadata > dirMeta ;
2015-10-23 18:55:48 -04:00
var viewMeta = this . _viewResolver . resolve ( directiveType ) ;
2016-03-09 17:55:27 -05:00
assertArrayOfStrings ( 'styles' , viewMeta . styles ) ;
2016-05-25 15:46:22 -04:00
var animations = isPresent ( viewMeta . animations )
? viewMeta . animations . map ( e = > this . getAnimationEntryMetadata ( e ) )
: null ;
2015-09-18 13:33:23 -04:00
templateMeta = new cpl . CompileTemplateMetadata ( {
2015-10-23 18:55:48 -04:00
encapsulation : viewMeta.encapsulation ,
template : viewMeta.template ,
templateUrl : viewMeta.templateUrl ,
styles : viewMeta.styles ,
2016-05-25 15:46:22 -04:00
styleUrls : viewMeta.styleUrls ,
animations : animations
2015-09-14 18:59:09 -04:00
} ) ;
2015-10-23 18:55:48 -04:00
changeDetectionStrategy = cmpMeta . changeDetection ;
2016-01-06 17:13:44 -05:00
if ( isPresent ( dirMeta . viewProviders ) ) {
viewProviders = this . getProvidersMetadata ( dirMeta . viewProviders ) ;
}
2016-05-02 19:45:43 -04:00
module Url = componentModuleUrl ( this . _reflector , directiveType , cmpMeta ) ;
2016-01-06 17:13:44 -05:00
}
2016-06-08 18:45:15 -04:00
var providers : any [ ] /** TODO #9100 */ = [ ] ;
2016-01-06 17:13:44 -05:00
if ( isPresent ( dirMeta . providers ) ) {
providers = this . getProvidersMetadata ( dirMeta . providers ) ;
}
2016-06-08 18:45:15 -04:00
var queries : any [ ] /** TODO #9100 */ = [ ] ;
var viewQueries : any [ ] /** TODO #9100 */ = [ ] ;
2016-01-06 17:13:44 -05:00
if ( isPresent ( dirMeta . queries ) ) {
2016-06-04 22:46:03 -04:00
queries = this . getQueriesMetadata ( dirMeta . queries , false , directiveType ) ;
viewQueries = this . getQueriesMetadata ( dirMeta . queries , true , directiveType ) ;
2015-09-14 18:59:09 -04:00
}
2015-09-18 13:33:23 -04:00
meta = cpl . CompileDirectiveMetadata . create ( {
2015-10-23 18:55:48 -04:00
selector : dirMeta.selector ,
exportAs : dirMeta.exportAs ,
2015-09-14 18:59:09 -04:00
isComponent : isPresent ( templateMeta ) ,
2016-05-02 19:45:43 -04:00
type : this . getTypeMetadata ( directiveType , module Url ) ,
2015-09-14 18:59:09 -04:00
template : templateMeta ,
2015-09-18 13:33:23 -04:00
changeDetection : changeDetectionStrategy ,
2015-10-23 18:55:48 -04:00
inputs : dirMeta.inputs ,
outputs : dirMeta.outputs ,
host : dirMeta.host ,
2016-01-06 17:13:44 -05:00
lifecycleHooks :
LIFECYCLE_HOOKS_VALUES . filter ( hook = > hasLifecycleHook ( hook , directiveType ) ) ,
providers : providers ,
viewProviders : viewProviders ,
queries : queries ,
viewQueries : viewQueries
2015-09-14 18:59:09 -04:00
} ) ;
2015-12-02 13:35:51 -05:00
this . _directiveCache . set ( directiveType , meta ) ;
}
return meta ;
}
2016-02-18 13:53:21 -05:00
/ * *
* @param someType a symbol which may or may not be a directive type
* @returns { cpl . CompileDirectiveMetadata } if possible , otherwise null .
* /
maybeGetDirectiveMetadata ( someType : Type ) : cpl . CompileDirectiveMetadata {
try {
return this . getDirectiveMetadata ( someType ) ;
} catch ( e ) {
if ( e . message . indexOf ( 'No Directive annotation' ) !== - 1 ) {
return null ;
}
throw e ;
}
}
2016-01-06 17:13:44 -05:00
getTypeMetadata ( type : Type , module Url : string ) : cpl . CompileTypeMetadata {
return new cpl . CompileTypeMetadata ( {
2016-04-20 21:10:19 -04:00
name : this.sanitizeTokenName ( type ) ,
2016-01-06 17:13:44 -05:00
module Url : module Url ,
runtime : type ,
diDeps : this.getDependenciesMetadata ( type , null )
} ) ;
}
getFactoryMetadata ( factory : Function , module Url : string ) : cpl . CompileFactoryMetadata {
return new cpl . CompileFactoryMetadata ( {
2016-04-20 21:10:19 -04:00
name : this.sanitizeTokenName ( factory ) ,
2016-01-06 17:13:44 -05:00
module Url : module Url ,
runtime : factory ,
diDeps : this.getDependenciesMetadata ( factory , null )
} ) ;
}
2015-12-02 13:35:51 -05:00
getPipeMetadata ( pipeType : Type ) : cpl . CompilePipeMetadata {
var meta = this . _pipeCache . get ( pipeType ) ;
if ( isBlank ( meta ) ) {
var pipeMeta = this . _pipeResolver . resolve ( pipeType ) ;
meta = new cpl . CompilePipeMetadata ( {
2016-02-18 13:53:21 -05:00
type : this . getTypeMetadata ( pipeType , staticTypeModuleUrl ( pipeType ) ) ,
2015-12-02 13:35:51 -05:00
name : pipeMeta.name ,
2016-01-06 17:13:44 -05:00
pure : pipeMeta.pure ,
lifecycleHooks : LIFECYCLE_HOOKS_VALUES.filter ( hook = > hasLifecycleHook ( hook , pipeType ) ) ,
2015-12-02 13:35:51 -05:00
} ) ;
this . _pipeCache . set ( pipeType , meta ) ;
2015-09-14 18:59:09 -04:00
}
return meta ;
}
2015-09-18 13:33:23 -04:00
getViewDirectivesMetadata ( component : Type ) : cpl . CompileDirectiveMetadata [ ] {
2015-09-14 18:59:09 -04:00
var view = this . _viewResolver . resolve ( component ) ;
2015-11-09 17:33:22 -05:00
var directives = flattenDirectives ( view , this . _platformDirectives ) ;
2015-09-14 18:59:09 -04:00
for ( var i = 0 ; i < directives . length ; i ++ ) {
2015-12-02 13:35:51 -05:00
if ( ! isValidType ( directives [ i ] ) ) {
2015-09-14 18:59:09 -04:00
throw new BaseException (
` Unexpected directive value ' ${ stringify ( directives [ i ] ) } ' on the View of component ' ${ stringify ( component ) } ' ` ) ;
}
}
2015-12-02 13:35:51 -05:00
return directives . map ( type = > this . getDirectiveMetadata ( type ) ) ;
}
getViewPipesMetadata ( component : Type ) : cpl . CompilePipeMetadata [ ] {
var view = this . _viewResolver . resolve ( component ) ;
var pipes = flattenPipes ( view , this . _platformPipes ) ;
for ( var i = 0 ; i < pipes . length ; i ++ ) {
if ( ! isValidType ( pipes [ i ] ) ) {
throw new BaseException (
` Unexpected piped value ' ${ stringify ( pipes [ i ] ) } ' on the View of component ' ${ stringify ( component ) } ' ` ) ;
}
}
return pipes . map ( type = > this . getPipeMetadata ( type ) ) ;
2015-09-14 18:59:09 -04:00
}
2016-01-06 17:13:44 -05:00
getDependenciesMetadata ( typeOrFunc : Type | Function ,
dependencies : any [ ] ) : cpl . CompileDiDependencyMetadata [ ] {
2016-06-09 19:07:06 -04:00
let hasUnknownDeps = false ;
2016-02-18 13:53:21 -05:00
let params = isPresent ( dependencies ) ? dependencies : this._reflector.parameters ( typeOrFunc ) ;
if ( isBlank ( params ) ) {
params = [ ] ;
2016-01-06 17:13:44 -05:00
}
2016-06-09 19:07:06 -04:00
let dependenciesMetadata : cpl.CompileDiDependencyMetadata [ ] = params . map ( ( param ) = > {
2016-02-18 13:53:21 -05:00
if ( isBlank ( param ) ) {
return null ;
}
let isAttribute = false ;
let isHost = false ;
let isSelf = false ;
let isSkipSelf = false ;
let isOptional = false ;
2016-04-28 20:50:03 -04:00
let query : QueryMetadata = null ;
let viewQuery : ViewQueryMetadata = null ;
2016-06-08 18:45:15 -04:00
var token : any /** TODO #9100 */ = null ;
2016-02-18 13:53:21 -05:00
if ( isArray ( param ) ) {
( < any [ ] > param )
. forEach ( ( paramEntry ) = > {
if ( paramEntry instanceof HostMetadata ) {
isHost = true ;
} else if ( paramEntry instanceof SelfMetadata ) {
isSelf = true ;
} else if ( paramEntry instanceof SkipSelfMetadata ) {
isSkipSelf = true ;
} else if ( paramEntry instanceof OptionalMetadata ) {
isOptional = true ;
} else if ( paramEntry instanceof AttributeMetadata ) {
isAttribute = true ;
token = paramEntry . attributeName ;
} else if ( paramEntry instanceof QueryMetadata ) {
if ( paramEntry . isViewQuery ) {
viewQuery = paramEntry ;
} else {
query = paramEntry ;
}
} else if ( paramEntry instanceof InjectMetadata ) {
token = paramEntry . token ;
} else if ( isValidType ( paramEntry ) && isBlank ( token ) ) {
token = paramEntry ;
}
} ) ;
2016-01-06 17:13:44 -05:00
} else {
2016-02-18 13:53:21 -05:00
token = param ;
2016-01-06 17:13:44 -05:00
}
2016-02-18 13:53:21 -05:00
if ( isBlank ( token ) ) {
2016-06-09 19:07:06 -04:00
hasUnknownDeps = true ;
2016-02-18 13:53:21 -05:00
return null ;
2016-01-06 17:13:44 -05:00
}
return new cpl . CompileDiDependencyMetadata ( {
isAttribute : isAttribute ,
2016-02-18 13:53:21 -05:00
isHost : isHost ,
isSelf : isSelf ,
isSkipSelf : isSkipSelf ,
isOptional : isOptional ,
2016-06-04 22:46:03 -04:00
query : isPresent ( query ) ? this . getQueryMetadata ( query , null , typeOrFunc ) : null ,
viewQuery : isPresent ( viewQuery ) ? this . getQueryMetadata ( viewQuery , null , typeOrFunc ) : null ,
2016-02-18 13:53:21 -05:00
token : this.getTokenMetadata ( token )
2016-01-06 17:13:44 -05:00
} ) ;
2016-02-18 13:53:21 -05:00
2016-01-06 17:13:44 -05:00
} ) ;
2016-06-09 19:07:06 -04:00
if ( hasUnknownDeps ) {
let depsTokens = dependenciesMetadata . map ( ( dep ) = > {
return dep ? stringify ( dep . token ) : '?' ;
} ) . join ( ', ' ) ;
throw new BaseException ( ` Can't resolve all parameters for ${ stringify ( typeOrFunc ) } : ( ${ depsTokens } ). ` ) ;
}
return dependenciesMetadata ;
2016-01-06 17:13:44 -05:00
}
getTokenMetadata ( token : any ) : cpl . CompileTokenMetadata {
token = resolveForwardRef ( token ) ;
2016-06-08 18:45:15 -04:00
var compileToken : any /** TODO #9100 */ ;
2016-01-06 17:13:44 -05:00
if ( isString ( token ) ) {
compileToken = new cpl . CompileTokenMetadata ( { value : token } ) ;
} else {
2016-04-20 21:10:19 -04:00
compileToken = new cpl . CompileTokenMetadata ( {
2016-02-18 13:53:21 -05:00
identifier : new cpl . CompileIdentifierMetadata ( {
runtime : token ,
name : this.sanitizeTokenName ( token ) ,
module Url : staticTypeModuleUrl ( token )
} )
2016-04-20 21:10:19 -04:00
} ) ;
2016-01-06 17:13:44 -05:00
}
return compileToken ;
}
getProvidersMetadata ( providers : any [ ] ) :
Array < cpl.CompileProviderMetadata | cpl.CompileTypeMetadata | any [ ] > {
return providers . map ( ( provider ) = > {
provider = resolveForwardRef ( provider ) ;
if ( isArray ( provider ) ) {
return this . getProvidersMetadata ( provider ) ;
} else if ( provider instanceof Provider ) {
return this . getProviderMetadata ( provider ) ;
2016-04-26 01:25:21 -04:00
} else if ( isProviderLiteral ( provider ) ) {
return this . getProviderMetadata ( createProvider ( provider ) ) ;
2016-01-06 17:13:44 -05:00
} else {
2016-02-18 13:53:21 -05:00
return this . getTypeMetadata ( provider , staticTypeModuleUrl ( provider ) ) ;
2016-01-06 17:13:44 -05:00
}
} ) ;
}
getProviderMetadata ( provider : Provider ) : cpl . CompileProviderMetadata {
2016-06-08 18:45:15 -04:00
var compileDeps : any /** TODO #9100 */ ;
2016-01-06 17:13:44 -05:00
if ( isPresent ( provider . useClass ) ) {
compileDeps = this . getDependenciesMetadata ( provider . useClass , provider . dependencies ) ;
} else if ( isPresent ( provider . useFactory ) ) {
compileDeps = this . getDependenciesMetadata ( provider . useFactory , provider . dependencies ) ;
}
return new cpl . CompileProviderMetadata ( {
token : this.getTokenMetadata ( provider . token ) ,
2016-02-18 13:53:21 -05:00
useClass :
isPresent ( provider . useClass ) ?
this . getTypeMetadata ( provider . useClass , staticTypeModuleUrl ( provider . useClass ) ) :
null ,
2016-04-30 19:13:03 -04:00
useValue : convertToCompileValue ( provider . useValue ) ,
2016-01-06 17:13:44 -05:00
useFactory : isPresent ( provider . useFactory ) ?
2016-02-18 13:53:21 -05:00
this . getFactoryMetadata ( provider . useFactory ,
staticTypeModuleUrl ( provider . useFactory ) ) :
2016-01-06 17:13:44 -05:00
null ,
useExisting : isPresent ( provider . useExisting ) ? this . getTokenMetadata ( provider . useExisting ) :
null ,
deps : compileDeps ,
multi : provider.multi
} ) ;
}
2016-04-28 20:50:03 -04:00
getQueriesMetadata ( queries : { [ key : string ] : QueryMetadata } ,
2016-06-04 22:46:03 -04:00
isViewQuery : boolean , directiveType : Type ) : cpl . CompileQueryMetadata [ ] {
2016-06-08 18:45:15 -04:00
var compileQueries : any [ ] /** TODO #9100 */ = [ ] ;
StringMapWrapper . forEach ( queries , ( query : any /** TODO #9100 */ , propertyName : any /** TODO #9100 */ ) = > {
2016-01-06 17:13:44 -05:00
if ( query . isViewQuery === isViewQuery ) {
2016-06-04 22:46:03 -04:00
compileQueries . push ( this . getQueryMetadata ( query , propertyName , directiveType ) ) ;
2016-01-06 17:13:44 -05:00
}
} ) ;
return compileQueries ;
}
2016-06-04 22:46:03 -04:00
getQueryMetadata ( q : QueryMetadata , propertyName : string , typeOrFunc : Type | Function ) : cpl . CompileQueryMetadata {
2016-06-08 18:45:15 -04:00
var selectors : any /** TODO #9100 */ ;
2016-01-06 17:13:44 -05:00
if ( q . isVarBindingQuery ) {
selectors = q . varBindings . map ( varName = > this . getTokenMetadata ( varName ) ) ;
} else {
2016-06-04 22:46:03 -04:00
if ( ! isPresent ( q . selector ) ) {
throw new BaseException ( ` Can't construct a query for the property " ${ propertyName } " of " ${ stringify ( typeOrFunc ) } " since the query selector wasn't defined. ` ) ;
}
2016-01-06 17:13:44 -05:00
selectors = [ this . getTokenMetadata ( q . selector ) ] ;
}
return new cpl . CompileQueryMetadata ( {
selectors : selectors ,
first : q.first ,
descendants : q.descendants ,
2016-04-18 16:24:42 -04:00
propertyName : propertyName ,
read : isPresent ( q . read ) ? this . getTokenMetadata ( q . read ) : null
2016-01-06 17:13:44 -05:00
} ) ;
}
2015-09-14 18:59:09 -04:00
}
2015-11-09 17:33:22 -05:00
function flattenDirectives ( view : ViewMetadata , platformDirectives : any [ ] ) : Type [ ] {
2016-06-08 18:45:15 -04:00
let directives : any [ ] /** TODO #9100 */ = [ ] ;
2015-11-09 17:33:22 -05:00
if ( isPresent ( platformDirectives ) ) {
flattenArray ( platformDirectives , directives ) ;
2015-11-02 19:03:42 -05:00
}
if ( isPresent ( view . directives ) ) {
flattenArray ( view . directives , directives ) ;
}
2015-09-14 18:59:09 -04:00
return directives ;
}
2015-12-02 13:35:51 -05:00
function flattenPipes ( view : ViewMetadata , platformPipes : any [ ] ) : Type [ ] {
2016-06-08 18:45:15 -04:00
let pipes : any [ ] /** TODO #9100 */ = [ ] ;
2015-12-02 13:35:51 -05:00
if ( isPresent ( platformPipes ) ) {
flattenArray ( platformPipes , pipes ) ;
}
if ( isPresent ( view . pipes ) ) {
flattenArray ( view . pipes , pipes ) ;
}
return pipes ;
}
2016-04-12 12:40:37 -04:00
function flattenArray ( tree : any [ ] , out : Array < Type | any [ ] > ) : void {
2015-09-14 18:59:09 -04:00
for ( var i = 0 ; i < tree . length ; i ++ ) {
var item = resolveForwardRef ( tree [ i ] ) ;
if ( isArray ( item ) ) {
2015-11-02 19:03:42 -05:00
flattenArray ( item , out ) ;
2015-09-14 18:59:09 -04:00
} else {
out . push ( item ) ;
}
}
}
2016-02-18 13:53:21 -05:00
function isStaticType ( value : any ) : boolean {
2016-05-02 12:38:46 -04:00
return isStringMap ( value ) && isPresent ( value [ 'name' ] ) && isPresent ( value [ 'filePath' ] ) ;
2016-02-18 13:53:21 -05:00
}
function isValidType ( value : any ) : boolean {
return isStaticType ( value ) || ( value instanceof Type ) ;
}
function staticTypeModuleUrl ( value : any ) : string {
2016-05-02 12:38:46 -04:00
return isStaticType ( value ) ? value [ 'filePath' ] : null ;
2015-09-14 18:59:09 -04:00
}
2016-05-02 12:38:46 -04:00
function componentModuleUrl ( reflector : ReflectorReader , type : any ,
cmpMetadata : ComponentMetadata ) : string {
2016-04-29 00:54:02 -04:00
if ( isStaticType ( type ) ) {
2016-05-02 12:38:46 -04:00
return staticTypeModuleUrl ( type ) ;
2016-04-29 00:54:02 -04:00
}
if ( isPresent ( cmpMetadata . module Id ) ) {
var module Id = cmpMetadata . module Id ;
2015-12-05 05:21:38 -05:00
var scheme = getUrlScheme ( module Id ) ;
return isPresent ( scheme ) && scheme . length > 0 ? module Id :
2016-05-02 01:50:37 -04:00
` package: ${ module Id } ${ MODULE_SUFFIX } ` ;
2015-09-14 18:59:09 -04:00
}
2016-04-29 00:54:02 -04:00
return reflector . importUri ( type ) ;
2015-09-14 18:59:09 -04:00
}
2016-04-30 19:13:03 -04:00
// Only fill CompileIdentifierMetadata.runtime if needed...
function convertToCompileValue ( value : any ) : any {
return visitValue ( value , new _CompileValueConverter ( ) , null ) ;
}
class _CompileValueConverter extends ValueTransformer {
visitOther ( value : any , context : any ) : any {
if ( isStaticType ( value ) ) {
return new cpl . CompileIdentifierMetadata (
{ name : value [ 'name' ] , module Url : staticTypeModuleUrl ( value ) } ) ;
} else {
return new cpl . CompileIdentifierMetadata ( { runtime : value } ) ;
}
}
}