| 
									
										
										
										
											2017-03-15 15:50:30 -07:00
										 |  |  | /** | 
					
						
							|  |  |  |  * @license | 
					
						
							| 
									
										
										
										
											2020-05-19 12:08:49 -07:00
										 |  |  |  * Copyright Google LLC All Rights Reserved. | 
					
						
							| 
									
										
										
										
											2017-03-15 15:50:30 -07:00
										 |  |  |  * | 
					
						
							|  |  |  |  * 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
 | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | import './init'; | 
					
						
							|  |  |  | import {BindingErrorComp} from '../src/errors'; | 
					
						
							|  |  |  | import {createComponent} from './util'; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-08-02 11:20:07 -07:00
										 |  |  | // TODO(tbosch): source maps does not currently work with the transformer pipeline
 | 
					
						
							|  |  |  | xdescribe('source maps', () => { | 
					
						
							| 
									
										
										
										
											2017-03-15 15:50:30 -07:00
										 |  |  |   it('should report source location for binding errors', () => { | 
					
						
							|  |  |  |     const comp = createComponent(BindingErrorComp); | 
					
						
							|  |  |  |     let error: any; | 
					
						
							|  |  |  |     try { | 
					
						
							|  |  |  |       comp.detectChanges(); | 
					
						
							|  |  |  |     } catch (e) { | 
					
						
							|  |  |  |       error = e; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     const sourcePosition = getSourcePositionForStack(error.stack); | 
					
						
							|  |  |  |     expect(sourcePosition.line).toBe(2); | 
					
						
							|  |  |  |     expect(sourcePosition.column).toBe(13); | 
					
						
							|  |  |  |     expect(sourcePosition.source.endsWith('errors.html')).toBe(true); | 
					
						
							|  |  |  |   }); | 
					
						
							|  |  |  | }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | function getSourcePositionForStack(stack: string): {source: string, line: number, column: number} { | 
					
						
							|  |  |  |   const htmlLocations = stack | 
					
						
							|  |  |  |                             .split('\n') | 
					
						
							|  |  |  |                             // e.g. at View_MyComp_0 (...html:153:40)
 | 
					
						
							| 
									
										
										
										
											2020-04-07 12:43:43 -07:00
										 |  |  |                             .map(line => /\((.*\.html):(\d+):(\d+)/.exec(line)!) | 
					
						
							| 
									
										
										
										
											2017-03-15 15:50:30 -07:00
										 |  |  |                             .filter(match => !!match) | 
					
						
							|  |  |  |                             .map(match => ({ | 
					
						
							|  |  |  |                                    source: match[1], | 
					
						
							|  |  |  |                                    line: parseInt(match[2], 10), | 
					
						
							|  |  |  |                                    column: parseInt(match[3], 10) | 
					
						
							|  |  |  |                                  })); | 
					
						
							|  |  |  |   return htmlLocations[0]; | 
					
						
							|  |  |  | } |