@@ -27,12 +27,30 @@ import {getUrlScheme} from 'angular2/src/compiler/url_resolver';
2727export class RuntimeMetadataResolver {
2828 private _directiveCache = new Map < Type , cpl . CompileDirectiveMetadata > ( ) ;
2929 private _pipeCache = new Map < Type , cpl . CompilePipeMetadata > ( ) ;
30+ private _anonymousTypes = new Map < Object , number > ( ) ;
31+ private _anonymousTypeIndex = 0 ;
3032
3133 constructor ( private _directiveResolver : DirectiveResolver , private _pipeResolver : PipeResolver ,
3234 private _viewResolver : ViewResolver ,
3335 @Optional ( ) @Inject ( PLATFORM_DIRECTIVES ) private _platformDirectives : Type [ ] ,
3436 @Optional ( ) @Inject ( PLATFORM_PIPES ) private _platformPipes : Type [ ] ) { }
3537
38+ /**
39+ * Wrap the stringify method to avoid naming things `function (arg1...) {`
40+ */
41+ private sanitizeName ( obj : any ) : string {
42+ let result = stringify ( obj ) ;
43+ if ( result . indexOf ( '(' ) < 0 ) {
44+ return result ;
45+ }
46+ let found = this . _anonymousTypes . get ( obj ) ;
47+ if ( ! found ) {
48+ this . _anonymousTypes . set ( obj , this . _anonymousTypeIndex ++ ) ;
49+ found = this . _anonymousTypes . get ( obj ) ;
50+ }
51+ return `anonymous_type_${ found } _` ;
52+ }
53+
3654 getDirectiveMetadata ( directiveType : Type ) : cpl . CompileDirectiveMetadata {
3755 var meta = this . _directiveCache . get ( directiveType ) ;
3856 if ( isBlank ( meta ) ) {
@@ -62,7 +80,7 @@ export class RuntimeMetadataResolver {
6280 isComponent : isPresent ( templateMeta ) ,
6381 dynamicLoadable : true ,
6482 type : new cpl . CompileTypeMetadata (
65- { name : stringify ( directiveType ) , moduleUrl : moduleUrl , runtime : directiveType } ) ,
83+ { name : this . sanitizeName ( directiveType ) , moduleUrl : moduleUrl , runtime : directiveType } ) ,
6684 template : templateMeta ,
6785 changeDetection : changeDetectionStrategy ,
6886 inputs : dirMeta . inputs ,
@@ -82,7 +100,7 @@ export class RuntimeMetadataResolver {
82100 var moduleUrl = reflector . importUri ( pipeType ) ;
83101 meta = new cpl . CompilePipeMetadata ( {
84102 type : new cpl . CompileTypeMetadata (
85- { name : stringify ( pipeType ) , moduleUrl : moduleUrl , runtime : pipeType } ) ,
103+ { name : this . sanitizeName ( pipeType ) , moduleUrl : moduleUrl , runtime : pipeType } ) ,
86104 name : pipeMeta . name ,
87105 pure : pipeMeta . pure
88106 } ) ;
0 commit comments