7
7
isStringMap ,
8
8
FunctionWrapper
9
9
} from 'angular2/src/facade/lang' ;
10
- import { BaseException } from 'angular2/src/facade/exceptions' ;
11
10
import {
12
11
AttributeMetadata ,
13
12
DirectiveMetadata ,
@@ -35,11 +34,6 @@ import {
35
34
SkipSelfMetadata ,
36
35
InjectMetadata ,
37
36
} 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
- }
43
37
44
38
/**
45
39
* 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 {
71
65
*
72
66
* This token is unique for a moduleId and name and can be used as a hash table key.
73
67
*/
74
- export class StaticSymbol implements ModuleContext {
68
+ export class StaticSymbol {
75
69
constructor ( public moduleId : string , public filePath : string , public name : string ) { }
76
70
}
77
71
@@ -84,8 +78,7 @@ export class StaticReflector implements ReflectorReader {
84
78
private propertyCache = new Map < StaticSymbol , { [ key : string ] : any } > ( ) ;
85
79
private parameterCache = new Map < StaticSymbol , any [ ] > ( ) ;
86
80
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 > ( ) ;
89
82
90
83
constructor ( private host : StaticReflectorHost ) { this . initializeConversionMap ( ) ; }
91
84
@@ -155,22 +148,20 @@ export class StaticReflector implements ReflectorReader {
155
148
}
156
149
return parameters ;
157
150
} catch ( e ) {
158
- console . error ( ' Failed on type' , type , ' with error' , e ) ;
151
+ console . log ( ` Failed on type ${ type } with error ${ e } ` ) ;
159
152
throw e ;
160
153
}
161
154
}
162
155
163
156
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 [ ] ) => {
165
158
let argValues = [ ] ;
166
159
ListWrapper . forEachWithIndex ( args , ( arg , index ) => {
167
160
let argValue ;
168
161
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 ) ) ;
172
163
} else {
173
- argValue = this . simplify ( moduleContext , arg ) ;
164
+ argValue = this . simplify ( context , arg ) ;
174
165
}
175
166
argValues . push ( argValue ) ;
176
167
} ) ;
@@ -183,7 +174,6 @@ export class StaticReflector implements ReflectorReader {
183
174
let diDecorators = 'angular2/src/core/di/decorators' ;
184
175
let diMetadata = 'angular2/src/core/di/metadata' ;
185
176
let provider = 'angular2/src/core/di/provider' ;
186
- let opaqueToken = 'angular2/src/core/di/opaque_token' ;
187
177
this . registerDecoratorOrConstructor ( this . host . findDeclaration ( provider , 'Provider' ) , Provider ) ;
188
178
189
179
this . registerDecoratorOrConstructor ( this . host . findDeclaration ( diDecorators , 'Host' ) ,
@@ -236,12 +226,10 @@ export class StaticReflector implements ReflectorReader {
236
226
SkipSelfMetadata ) ;
237
227
this . registerDecoratorOrConstructor ( this . host . findDeclaration ( diMetadata , 'OptionalMetadata' ) ,
238
228
OptionalMetadata ) ;
239
- this . registerDecoratorOrConstructor ( this . host . findDeclaration ( opaqueToken , 'OpaqueToken' ) ,
240
- OpaqueToken ) ;
241
229
}
242
230
243
231
/** @internal */
244
- public simplify ( moduleContext : ModuleContext , value : any ) : any {
232
+ public simplify ( context : StaticSymbol , value : any ) : any {
245
233
let _this = this ;
246
234
247
235
function simplify ( expression : any ) : any {
@@ -331,41 +319,39 @@ export class StaticReflector implements ReflectorReader {
331
319
case "reference" :
332
320
if ( isPresent ( expression [ 'module' ] ) ) {
333
321
staticSymbol = _this . host . findDeclaration ( expression [ 'module' ] , expression [ 'name' ] ,
334
- moduleContext . filePath ) ;
322
+ context . filePath ) ;
335
323
} 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' ] ) ;
338
326
}
339
327
let result = staticSymbol ;
340
328
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 ;
342
331
if ( isPresent ( declarationValue ) ) {
343
332
if ( isClassMetadata ( declarationValue ) ) {
344
333
result = staticSymbol ;
345
334
} else {
346
- let newModuleContext =
347
- new ModuleContext ( staticSymbol . moduleId , staticSymbol . filePath ) ;
348
- result = _this . simplify ( newModuleContext , declarationValue ) ;
335
+ result = _this . simplify ( staticSymbol , declarationValue ) ;
349
336
}
350
337
}
351
338
return result ;
339
+ case "class" :
340
+ return context ;
352
341
case "new" :
353
342
case "call" :
354
343
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 ) ;
357
346
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
- }
361
347
if ( isPresent ( converter ) ) {
362
348
let args = expression [ 'arguments' ] ;
363
349
if ( isBlank ( args ) ) {
364
350
args = [ ] ;
365
351
}
366
- return converter ( moduleContext , args ) ;
352
+ return converter ( context , args ) ;
367
353
} else {
368
- return staticSymbol ;
354
+ return context ;
369
355
}
370
356
}
371
357
return null ;
0 commit comments