@@ -6,12 +6,12 @@ import {
66 isArray ,
77 stringify ,
88 isString ,
9+ isStringMap ,
910 RegExpWrapper ,
1011 StringWrapper
1112} from 'angular2/src/facade/lang' ;
1213import { StringMapWrapper } from 'angular2/src/facade/collection' ;
1314import { BaseException } from 'angular2/src/facade/exceptions' ;
14- import { NoAnnotationError } from 'angular2/src/core/di/reflective_exceptions' ;
1515import * as cpl from './compile_metadata' ;
1616import * as md from 'angular2/src/core/metadata/directives' ;
1717import * as dimd from 'angular2/src/core/metadata/di' ;
@@ -28,20 +28,18 @@ import {MODULE_SUFFIX, sanitizeIdentifier} from './util';
2828import { assertArrayOfStrings } from './assertions' ;
2929import { getUrlScheme } from 'angular2/src/compiler/url_resolver' ;
3030import { Provider } from 'angular2/src/core/di/provider' ;
31- import {
32- constructDependencies ,
33- ReflectiveDependency
34- } from 'angular2/src/core/di/reflective_provider' ;
3531import {
3632 OptionalMetadata ,
3733 SelfMetadata ,
3834 HostMetadata ,
39- SkipSelfMetadata
35+ SkipSelfMetadata ,
36+ InjectMetadata
4037} from 'angular2/src/core/di/metadata' ;
38+ import { AttributeMetadata , QueryMetadata } from 'angular2/src/core/metadata/di' ;
4139import { ReflectorReader } from 'angular2/src/core/reflection/reflector_reader' ;
4240
4341@Injectable ( )
44- export class RuntimeMetadataResolver {
42+ export class CompileMetadataResolver {
4543 private _directiveCache = new Map < Type , cpl . CompileDirectiveMetadata > ( ) ;
4644 private _pipeCache = new Map < Type , cpl . CompilePipeMetadata > ( ) ;
4745 private _anonymousTypes = new Map < Object , number > ( ) ;
@@ -78,7 +76,7 @@ export class RuntimeMetadataResolver {
7876 var meta = this . _directiveCache . get ( directiveType ) ;
7977 if ( isBlank ( meta ) ) {
8078 var dirMeta = this . _directiveResolver . resolve ( directiveType ) ;
81- var moduleUrl = null ;
79+ var moduleUrl = staticTypeModuleUrl ( directiveType ) ;
8280 var templateMeta = null ;
8381 var changeDetectionStrategy = null ;
8482 var viewProviders = [ ] ;
@@ -134,6 +132,21 @@ export class RuntimeMetadataResolver {
134132 return meta ;
135133 }
136134
135+ /**
136+ * @param someType a symbol which may or may not be a directive type
137+ * @returns {cpl.CompileDirectiveMetadata } if possible, otherwise null.
138+ */
139+ maybeGetDirectiveMetadata ( someType : Type ) : cpl . CompileDirectiveMetadata {
140+ try {
141+ return this . getDirectiveMetadata ( someType ) ;
142+ } catch ( e ) {
143+ if ( e . message . indexOf ( 'No Directive annotation' ) !== - 1 ) {
144+ return null ;
145+ }
146+ throw e ;
147+ }
148+ }
149+
137150 getTypeMetadata ( type : Type , moduleUrl : string ) : cpl . CompileTypeMetadata {
138151 return new cpl . CompileTypeMetadata ( {
139152 name : this . sanitizeTokenName ( type ) ,
@@ -156,9 +169,8 @@ export class RuntimeMetadataResolver {
156169 var meta = this . _pipeCache . get ( pipeType ) ;
157170 if ( isBlank ( meta ) ) {
158171 var pipeMeta = this . _pipeResolver . resolve ( pipeType ) ;
159- var moduleUrl = this . _reflector . importUri ( pipeType ) ;
160172 meta = new cpl . CompilePipeMetadata ( {
161- type : this . getTypeMetadata ( pipeType , moduleUrl ) ,
173+ type : this . getTypeMetadata ( pipeType , staticTypeModuleUrl ( pipeType ) ) ,
162174 name : pipeMeta . name ,
163175 pure : pipeMeta . pure ,
164176 lifecycleHooks : LIFECYCLE_HOOKS_VALUES . filter ( hook => hasLifecycleHook ( hook , pipeType ) ) ,
@@ -177,7 +189,6 @@ export class RuntimeMetadataResolver {
177189 `Unexpected directive value '${ stringify ( directives [ i ] ) } ' on the View of component '${ stringify ( component ) } '` ) ;
178190 }
179191 }
180-
181192 return directives . map ( type => this . getDirectiveMetadata ( type ) ) ;
182193 }
183194
@@ -195,41 +206,65 @@ export class RuntimeMetadataResolver {
195206
196207 getDependenciesMetadata ( typeOrFunc : Type | Function ,
197208 dependencies : any [ ] ) : cpl . CompileDiDependencyMetadata [ ] {
198- var deps : ReflectiveDependency [ ] ;
199- try {
200- deps = constructDependencies ( typeOrFunc , dependencies ) ;
201- } catch ( e ) {
202- if ( e instanceof NoAnnotationError ) {
203- deps = [ ] ;
204- } else {
205- throw e ;
206- }
209+ let params = isPresent ( dependencies ) ? dependencies : this . _reflector . parameters ( typeOrFunc ) ;
210+ if ( isBlank ( params ) ) {
211+ params = [ ] ;
207212 }
208- return deps . map ( ( dep ) => {
209- var compileToken ;
210- var p = < dimd . AttributeMetadata > dep . properties . find ( p => p instanceof dimd . AttributeMetadata ) ;
211- var isAttribute = false ;
212- if ( isPresent ( p ) ) {
213- compileToken = this . getTokenMetadata ( p . attributeName ) ;
214- isAttribute = true ;
213+ return params . map ( ( param ) => {
214+ if ( isBlank ( param ) ) {
215+ return null ;
216+ }
217+ let isAttribute = false ;
218+ let isHost = false ;
219+ let isSelf = false ;
220+ let isSkipSelf = false ;
221+ let isOptional = false ;
222+ let query : dimd . QueryMetadata = null ;
223+ let viewQuery : dimd . ViewQueryMetadata = null ;
224+ var token = null ;
225+ if ( isArray ( param ) ) {
226+ ( < any [ ] > param )
227+ . forEach ( ( paramEntry ) => {
228+ if ( paramEntry instanceof HostMetadata ) {
229+ isHost = true ;
230+ } else if ( paramEntry instanceof SelfMetadata ) {
231+ isSelf = true ;
232+ } else if ( paramEntry instanceof SkipSelfMetadata ) {
233+ isSkipSelf = true ;
234+ } else if ( paramEntry instanceof OptionalMetadata ) {
235+ isOptional = true ;
236+ } else if ( paramEntry instanceof AttributeMetadata ) {
237+ isAttribute = true ;
238+ token = paramEntry . attributeName ;
239+ } else if ( paramEntry instanceof QueryMetadata ) {
240+ if ( paramEntry . isViewQuery ) {
241+ viewQuery = paramEntry ;
242+ } else {
243+ query = paramEntry ;
244+ }
245+ } else if ( paramEntry instanceof InjectMetadata ) {
246+ token = paramEntry . token ;
247+ } else if ( isValidType ( paramEntry ) && isBlank ( token ) ) {
248+ token = paramEntry ;
249+ }
250+ } ) ;
215251 } else {
216- compileToken = this . getTokenMetadata ( dep . key . token ) ;
252+ token = param ;
217253 }
218- var compileQuery = null ;
219- var q = < dimd . QueryMetadata > dep . properties . find ( p => p instanceof dimd . QueryMetadata ) ;
220- if ( isPresent ( q ) ) {
221- compileQuery = this . getQueryMetadata ( q , null ) ;
254+ if ( isBlank ( token ) ) {
255+ return null ;
222256 }
223257 return new cpl . CompileDiDependencyMetadata ( {
224258 isAttribute : isAttribute ,
225- isHost : dep . upperBoundVisibility instanceof HostMetadata ,
226- isSelf : dep . upperBoundVisibility instanceof SelfMetadata ,
227- isSkipSelf : dep . lowerBoundVisibility instanceof SkipSelfMetadata ,
228- isOptional : dep . optional ,
229- query : isPresent ( q ) && ! q . isViewQuery ? compileQuery : null ,
230- viewQuery : isPresent ( q ) && q . isViewQuery ? compileQuery : null ,
231- token : compileToken
259+ isHost : isHost ,
260+ isSelf : isSelf ,
261+ isSkipSelf : isSkipSelf ,
262+ isOptional : isOptional ,
263+ query : isPresent ( query ) ? this . getQueryMetadata ( query , null ) : null ,
264+ viewQuery : isPresent ( viewQuery ) ? this . getQueryMetadata ( viewQuery , null ) : null ,
265+ token : this . getTokenMetadata ( token )
232266 } ) ;
267+
233268 } ) ;
234269 }
235270
@@ -240,8 +275,11 @@ export class RuntimeMetadataResolver {
240275 compileToken = new cpl . CompileTokenMetadata ( { value : token } ) ;
241276 } else {
242277 compileToken = new cpl . CompileTokenMetadata ( {
243- identifier : new cpl . CompileIdentifierMetadata (
244- { runtime : token , name : this . sanitizeTokenName ( token ) } )
278+ identifier : new cpl . CompileIdentifierMetadata ( {
279+ runtime : token ,
280+ name : this . sanitizeTokenName ( token ) ,
281+ moduleUrl : staticTypeModuleUrl ( token )
282+ } )
245283 } ) ;
246284 }
247285 return compileToken ;
@@ -256,7 +294,7 @@ export class RuntimeMetadataResolver {
256294 } else if ( provider instanceof Provider ) {
257295 return this . getProviderMetadata ( provider ) ;
258296 } else {
259- return this . getTypeMetadata ( provider , null ) ;
297+ return this . getTypeMetadata ( provider , staticTypeModuleUrl ( provider ) ) ;
260298 }
261299 } ) ;
262300 }
@@ -270,12 +308,16 @@ export class RuntimeMetadataResolver {
270308 }
271309 return new cpl . CompileProviderMetadata ( {
272310 token : this . getTokenMetadata ( provider . token ) ,
273- useClass : isPresent ( provider . useClass ) ? this . getTypeMetadata ( provider . useClass , null ) : null ,
311+ useClass :
312+ isPresent ( provider . useClass ) ?
313+ this . getTypeMetadata ( provider . useClass , staticTypeModuleUrl ( provider . useClass ) ) :
314+ null ,
274315 useValue : isPresent ( provider . useValue ) ?
275316 new cpl . CompileIdentifierMetadata ( { runtime : provider . useValue } ) :
276317 null ,
277318 useFactory : isPresent ( provider . useFactory ) ?
278- this . getFactoryMetadata ( provider . useFactory , null ) :
319+ this . getFactoryMetadata ( provider . useFactory ,
320+ staticTypeModuleUrl ( provider . useFactory ) ) :
279321 null ,
280322 useExisting : isPresent ( provider . useExisting ) ? this . getTokenMetadata ( provider . useExisting ) :
281323 null ,
@@ -345,8 +387,16 @@ function flattenArray(tree: any[], out: Array<Type | any[]>): void {
345387 }
346388}
347389
348- function isValidType ( value : Type ) : boolean {
349- return isPresent ( value ) && ( value instanceof Type ) ;
390+ function isStaticType ( value : any ) : boolean {
391+ return isStringMap ( value ) && isPresent ( value [ 'name' ] ) && isPresent ( value [ 'moduleId' ] ) ;
392+ }
393+
394+ function isValidType ( value : any ) : boolean {
395+ return isStaticType ( value ) || ( value instanceof Type ) ;
396+ }
397+
398+ function staticTypeModuleUrl ( value : any ) : string {
399+ return isStaticType ( value ) ? value [ 'moduleId' ] : null ;
350400}
351401
352402function calcModuleUrl ( reflector : ReflectorReader , type : Type ,
0 commit comments