fix(codegen): stringify using an opaque ID when toString contains parens.
Using toString results in 'function (_arg1, arg2) {' when using closure compiler for 6-to-5.
Closes #7825
			
			
This commit is contained in:
		
							parent
							
								
									291928feb1
								
							
						
					
					
						commit
						90c87fa6ad
					
				| @ -27,12 +27,30 @@ import {getUrlScheme} from 'angular2/src/compiler/url_resolver'; | |||||||
| export class RuntimeMetadataResolver { | export class RuntimeMetadataResolver { | ||||||
|   private _directiveCache = new Map<Type, cpl.CompileDirectiveMetadata>(); |   private _directiveCache = new Map<Type, cpl.CompileDirectiveMetadata>(); | ||||||
|   private _pipeCache = new Map<Type, cpl.CompilePipeMetadata>(); |   private _pipeCache = new Map<Type, cpl.CompilePipeMetadata>(); | ||||||
|  |   private _anonymousTypes = new Map<Object, number>(); | ||||||
|  |   private _anonymousTypeIndex = 0; | ||||||
| 
 | 
 | ||||||
|   constructor(private _directiveResolver: DirectiveResolver, private _pipeResolver: PipeResolver, |   constructor(private _directiveResolver: DirectiveResolver, private _pipeResolver: PipeResolver, | ||||||
|               private _viewResolver: ViewResolver, |               private _viewResolver: ViewResolver, | ||||||
|               @Optional() @Inject(PLATFORM_DIRECTIVES) private _platformDirectives: Type[], |               @Optional() @Inject(PLATFORM_DIRECTIVES) private _platformDirectives: Type[], | ||||||
|               @Optional() @Inject(PLATFORM_PIPES) private _platformPipes: Type[]) {} |               @Optional() @Inject(PLATFORM_PIPES) private _platformPipes: Type[]) {} | ||||||
| 
 | 
 | ||||||
|  |   /** | ||||||
|  |    * Wrap the stringify method to avoid naming things `function (arg1...) {` | ||||||
|  |    */ | ||||||
|  |   private sanitizeName(obj: any): string { | ||||||
|  |     let result = stringify(obj); | ||||||
|  |     if (result.indexOf('(') < 0) { | ||||||
|  |       return result; | ||||||
|  |     } | ||||||
|  |     let found = this._anonymousTypes.get(obj); | ||||||
|  |     if (!found) { | ||||||
|  |       this._anonymousTypes.set(obj, this._anonymousTypeIndex++); | ||||||
|  |       found = this._anonymousTypes.get(obj); | ||||||
|  |     } | ||||||
|  |     return `anonymous_type_${found}_`; | ||||||
|  |   } | ||||||
|  | 
 | ||||||
|   getDirectiveMetadata(directiveType: Type): cpl.CompileDirectiveMetadata { |   getDirectiveMetadata(directiveType: Type): cpl.CompileDirectiveMetadata { | ||||||
|     var meta = this._directiveCache.get(directiveType); |     var meta = this._directiveCache.get(directiveType); | ||||||
|     if (isBlank(meta)) { |     if (isBlank(meta)) { | ||||||
| @ -62,7 +80,7 @@ export class RuntimeMetadataResolver { | |||||||
|         isComponent: isPresent(templateMeta), |         isComponent: isPresent(templateMeta), | ||||||
|         dynamicLoadable: true, |         dynamicLoadable: true, | ||||||
|         type: new cpl.CompileTypeMetadata( |         type: new cpl.CompileTypeMetadata( | ||||||
|             {name: stringify(directiveType), moduleUrl: moduleUrl, runtime: directiveType}), |             {name: this.sanitizeName(directiveType), moduleUrl: moduleUrl, runtime: directiveType}), | ||||||
|         template: templateMeta, |         template: templateMeta, | ||||||
|         changeDetection: changeDetectionStrategy, |         changeDetection: changeDetectionStrategy, | ||||||
|         inputs: dirMeta.inputs, |         inputs: dirMeta.inputs, | ||||||
| @ -82,7 +100,7 @@ export class RuntimeMetadataResolver { | |||||||
|       var moduleUrl = reflector.importUri(pipeType); |       var moduleUrl = reflector.importUri(pipeType); | ||||||
|       meta = new cpl.CompilePipeMetadata({ |       meta = new cpl.CompilePipeMetadata({ | ||||||
|         type: new cpl.CompileTypeMetadata( |         type: new cpl.CompileTypeMetadata( | ||||||
|             {name: stringify(pipeType), moduleUrl: moduleUrl, runtime: pipeType}), |             {name: this.sanitizeName(pipeType), moduleUrl: moduleUrl, runtime: pipeType}), | ||||||
|         name: pipeMeta.name, |         name: pipeMeta.name, | ||||||
|         pure: pipeMeta.pure |         pure: pipeMeta.pure | ||||||
|       }); |       }); | ||||||
|  | |||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user