| 
									
										
										
										
											2016-06-23 09:47:54 -07:00
										 |  |  | /** | 
					
						
							|  |  |  |  * @license | 
					
						
							|  |  |  |  * Copyright Google Inc. All Rights Reserved. | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * Use of this source code is governed by an MIT-style license that can be | 
					
						
							|  |  |  |  * found in the LICENSE file at https://angular.io/license
 | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-08-26 15:54:34 -07:00
										 |  |  | import {escapeIdentifier} from '@angular/compiler/src/output/abstract_emitter'; | 
					
						
							| 
									
										
										
										
											2016-01-06 14:13:44 -08:00
										 |  |  | 
 | 
					
						
							|  |  |  | export function main() { | 
					
						
							|  |  |  |   describe('AbstractEmitter', () => { | 
					
						
							| 
									
										
										
										
											2016-08-26 15:54:34 -07:00
										 |  |  |     describe('escapeIdentifier', () => { | 
					
						
							| 
									
										
										
										
											2016-01-06 14:13:44 -08:00
										 |  |  |       it('should escape single quotes', | 
					
						
							| 
									
										
										
										
											2016-08-26 15:54:34 -07:00
										 |  |  |          () => { expect(escapeIdentifier(`'`, false)).toEqual(`'\\''`); }); | 
					
						
							| 
									
										
										
										
											2016-01-06 14:13:44 -08:00
										 |  |  | 
 | 
					
						
							|  |  |  |       it('should escape backslash', | 
					
						
							| 
									
										
										
										
											2016-08-26 15:54:34 -07:00
										 |  |  |          () => { expect(escapeIdentifier('\\', false)).toEqual(`'\\\\'`); }); | 
					
						
							| 
									
										
										
										
											2016-01-06 14:13:44 -08:00
										 |  |  | 
 | 
					
						
							|  |  |  |       it('should escape newlines', | 
					
						
							| 
									
										
										
										
											2016-08-26 15:54:34 -07:00
										 |  |  |          () => { expect(escapeIdentifier('\n', false)).toEqual(`'\\n'`); }); | 
					
						
							| 
									
										
										
										
											2016-01-06 14:13:44 -08:00
										 |  |  | 
 | 
					
						
							|  |  |  |       it('should escape carriage returns', | 
					
						
							| 
									
										
										
										
											2016-08-26 15:54:34 -07:00
										 |  |  |          () => { expect(escapeIdentifier('\r', false)).toEqual(`'\\r'`); }); | 
					
						
							| 
									
										
										
										
											2016-01-06 14:13:44 -08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-08-26 15:54:34 -07:00
										 |  |  |       it('should escape $', () => { expect(escapeIdentifier('$', true)).toEqual(`'\\$'`); }); | 
					
						
							|  |  |  |       it('should not escape $', () => { expect(escapeIdentifier('$', false)).toEqual(`'$'`); }); | 
					
						
							|  |  |  |       it('should add quotes for non-identifiers', | 
					
						
							|  |  |  |          () => { expect(escapeIdentifier('==', false, false)).toEqual(`'=='`); }); | 
					
						
							|  |  |  |       it('does not escape class (but it probably should)', | 
					
						
							|  |  |  |          () => { expect(escapeIdentifier('class', false, false)).toEqual('class'); }); | 
					
						
							| 
									
										
										
										
											2016-01-06 14:13:44 -08:00
										 |  |  |     }); | 
					
						
							|  |  |  |   }); | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											2017-01-27 14:23:12 -08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-14 09:16:15 -07:00
										 |  |  | export function stripSourceMapAndNewLine(source: string): string { | 
					
						
							|  |  |  |   if (source.endsWith('\n')) { | 
					
						
							|  |  |  |     source = source.substring(0, source.length - 1); | 
					
						
							|  |  |  |   } | 
					
						
							| 
									
										
										
										
											2017-01-27 14:23:12 -08:00
										 |  |  |   const smi = source.lastIndexOf('\n//#'); | 
					
						
							|  |  |  |   if (smi == -1) return source; | 
					
						
							|  |  |  |   return source.slice(0, smi); | 
					
						
							|  |  |  | } |