77 isStringMap ,
88 FunctionWrapper
99} from 'angular2/src/facade/lang' ;
10- import { BaseException } from 'angular2/src/facade/exceptions' ;
1110import {
1211 AttributeMetadata ,
1312 DirectiveMetadata ,
@@ -35,11 +34,6 @@ import {
3534 SkipSelfMetadata ,
3635 InjectMetadata ,
3736} from "angular2/src/core/di/metadata" ;
38- import { OpaqueToken } from 'angular2/src/core/di/opaque_token' ;
39-
40- export class ModuleContext {
41- constructor ( public moduleId : string , public filePath : string ) { }
42- }
4337
4438/**
4539 * The host of the static resolver is expected to be able to provide module metadata in the form of
@@ -71,7 +65,7 @@ export interface StaticReflectorHost {
7165 *
7266 * This token is unique for a moduleId and name and can be used as a hash table key.
7367 */
74- export class StaticSymbol implements ModuleContext {
68+ export class StaticSymbol {
7569 constructor ( public moduleId : string , public filePath : string , public name : string ) { }
7670}
7771
@@ -84,8 +78,7 @@ export class StaticReflector implements ReflectorReader {
8478 private propertyCache = new Map < StaticSymbol , { [ key : string ] : any } > ( ) ;
8579 private parameterCache = new Map < StaticSymbol , any [ ] > ( ) ;
8680 private metadataCache = new Map < string , { [ key : string ] : any } > ( ) ;
87- private conversionMap =
88- new Map < StaticSymbol , ( moduleContext : ModuleContext , args : any [ ] ) => any > ( ) ;
81+ private conversionMap = new Map < StaticSymbol , ( context : StaticSymbol , args : any [ ] ) => any > ( ) ;
8982
9083 constructor ( private host : StaticReflectorHost ) { this . initializeConversionMap ( ) ; }
9184
@@ -155,22 +148,20 @@ export class StaticReflector implements ReflectorReader {
155148 }
156149 return parameters ;
157150 } catch ( e ) {
158- console . error ( ' Failed on type' , type , ' with error' , e ) ;
151+ console . log ( ` Failed on type ${ type } with error ${ e } ` ) ;
159152 throw e ;
160153 }
161154 }
162155
163156 private registerDecoratorOrConstructor ( type : StaticSymbol , ctor : any ) : void {
164- this . conversionMap . set ( type , ( moduleContext : ModuleContext , args : any [ ] ) => {
157+ this . conversionMap . set ( type , ( context : StaticSymbol , args : any [ ] ) => {
165158 let argValues = [ ] ;
166159 ListWrapper . forEachWithIndex ( args , ( arg , index ) => {
167160 let argValue ;
168161 if ( isStringMap ( arg ) && isBlank ( arg [ '__symbolic' ] ) ) {
169- argValue =
170- mapStringMap ( arg , ( value , key ) => this . simplify (
171- moduleContext , value ) ) ;
162+ argValue = mapStringMap ( arg , ( value , key ) => this . simplify ( context , value ) ) ;
172163 } else {
173- argValue = this . simplify ( moduleContext , arg ) ;
164+ argValue = this . simplify ( context , arg ) ;
174165 }
175166 argValues . push ( argValue ) ;
176167 } ) ;
@@ -183,7 +174,6 @@ export class StaticReflector implements ReflectorReader {
183174 let diDecorators = 'angular2/src/core/di/decorators' ;
184175 let diMetadata = 'angular2/src/core/di/metadata' ;
185176 let provider = 'angular2/src/core/di/provider' ;
186- let opaqueToken = 'angular2/src/core/di/opaque_token' ;
187177 this . registerDecoratorOrConstructor ( this . host . findDeclaration ( provider , 'Provider' ) , Provider ) ;
188178
189179 this . registerDecoratorOrConstructor ( this . host . findDeclaration ( diDecorators , 'Host' ) ,
@@ -236,12 +226,10 @@ export class StaticReflector implements ReflectorReader {
236226 SkipSelfMetadata ) ;
237227 this . registerDecoratorOrConstructor ( this . host . findDeclaration ( diMetadata , 'OptionalMetadata' ) ,
238228 OptionalMetadata ) ;
239- this . registerDecoratorOrConstructor ( this . host . findDeclaration ( opaqueToken , 'OpaqueToken' ) ,
240- OpaqueToken ) ;
241229 }
242230
243231 /** @internal */
244- public simplify ( moduleContext : ModuleContext , value : any ) : any {
232+ public simplify ( context : StaticSymbol , value : any ) : any {
245233 let _this = this ;
246234
247235 function simplify ( expression : any ) : any {
@@ -331,41 +319,39 @@ export class StaticReflector implements ReflectorReader {
331319 case "reference" :
332320 if ( isPresent ( expression [ 'module' ] ) ) {
333321 staticSymbol = _this . host . findDeclaration ( expression [ 'module' ] , expression [ 'name' ] ,
334- moduleContext . filePath ) ;
322+ context . filePath ) ;
335323 } else {
336- staticSymbol = _this . host . getStaticSymbol (
337- moduleContext . moduleId , moduleContext . filePath , expression [ 'name' ] ) ;
324+ staticSymbol = _this . host . getStaticSymbol ( context . moduleId , context . filePath ,
325+ expression [ 'name' ] ) ;
338326 }
339327 let result = staticSymbol ;
340328 let moduleMetadata = _this . getModuleMetadata ( staticSymbol . filePath ) ;
341- let declarationValue = isPresent ( moduleMetadata ) ? moduleMetadata [ 'metadata' ] [ staticSymbol . name ] : null ;
329+ let declarationValue =
330+ isPresent ( moduleMetadata ) ? moduleMetadata [ 'metadata' ] [ staticSymbol . name ] : null ;
342331 if ( isPresent ( declarationValue ) ) {
343332 if ( isClassMetadata ( declarationValue ) ) {
344333 result = staticSymbol ;
345334 } else {
346- let newModuleContext =
347- new ModuleContext ( staticSymbol . moduleId , staticSymbol . filePath ) ;
348- result = _this . simplify ( newModuleContext , declarationValue ) ;
335+ result = _this . simplify ( staticSymbol , declarationValue ) ;
349336 }
350337 }
351338 return result ;
339+ case "class" :
340+ return context ;
352341 case "new" :
353342 case "call" :
354343 let target = expression [ 'expression' ] ;
355- staticSymbol = _this . host . findDeclaration ( target [ 'module' ] , target [ 'name' ] ,
356- moduleContext . filePath ) ;
344+ staticSymbol =
345+ _this . host . findDeclaration ( target [ 'module' ] , target [ 'name' ] , context . filePath ) ;
357346 let converter = _this . conversionMap . get ( staticSymbol ) ;
358- if ( isBlank ( converter ) ) {
359- throw new BaseException ( `Cannot convert call/new expression for ${ target [ 'name' ] } in ${ moduleContext . filePath } ` )
360- }
361347 if ( isPresent ( converter ) ) {
362348 let args = expression [ 'arguments' ] ;
363349 if ( isBlank ( args ) ) {
364350 args = [ ] ;
365351 }
366- return converter ( moduleContext , args ) ;
352+ return converter ( context , args ) ;
367353 } else {
368- return staticSymbol ;
354+ return context ;
369355 }
370356 }
371357 return null ;
0 commit comments