| 
									
										
										
										
											2017-01-27 14:23:12 -08: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
 | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | import {StaticSymbol} from '@angular/compiler/src/aot/static_symbol'; | 
					
						
							|  |  |  | import {CompileIdentifierMetadata} from '@angular/compiler/src/compile_metadata'; | 
					
						
							|  |  |  | import {JavaScriptEmitter} from '@angular/compiler/src/output/js_emitter'; | 
					
						
							|  |  |  | import * as o from '@angular/compiler/src/output/output_ast'; | 
					
						
							|  |  |  | import {SourceMap} from '@angular/compiler/src/output/source_map'; | 
					
						
							|  |  |  | import {ParseLocation, ParseSourceFile, ParseSourceSpan} from '@angular/compiler/src/parse_util'; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-12-16 11:35:47 -08:00
										 |  |  | import {extractSourceMap, originalPositionFor} from '@angular/compiler/testing/src/output/source_map_util'; | 
					
						
							| 
									
										
										
										
											2017-01-27 14:23:12 -08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-15 15:50:30 -07:00
										 |  |  | const someGenFilePath = 'somePackage/someGenFile'; | 
					
						
							| 
									
										
										
										
											2017-01-27 14:23:12 -08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-12-16 14:42:55 -08:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2017-01-27 14:23:12 -08:00
										 |  |  |   describe('JavaScriptEmitter', () => { | 
					
						
							|  |  |  |     let emitter: JavaScriptEmitter; | 
					
						
							|  |  |  |     let someVar: o.ReadVarExpr; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-05-16 16:30:37 -07:00
										 |  |  |     beforeEach(() => { emitter = new JavaScriptEmitter(); }); | 
					
						
							| 
									
										
										
										
											2017-01-27 14:23:12 -08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-05-16 16:30:37 -07:00
										 |  |  |     function emitSourceMap(stmt: o.Statement | o.Statement[], preamble?: string): SourceMap { | 
					
						
							| 
									
										
										
										
											2017-01-27 14:23:12 -08:00
										 |  |  |       const stmts = Array.isArray(stmt) ? stmt : [stmt]; | 
					
						
							| 
									
										
										
										
											2017-10-04 13:37:27 -07:00
										 |  |  |       const source = emitter.emitStatements(someGenFilePath, stmts, preamble); | 
					
						
							| 
									
										
										
										
											2017-03-24 09:59:58 -07:00
										 |  |  |       return extractSourceMap(source) !; | 
					
						
							| 
									
										
										
										
											2017-01-27 14:23:12 -08:00
										 |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     describe('source maps', () => { | 
					
						
							|  |  |  |       it('should emit an inline source map', () => { | 
					
						
							|  |  |  |         const source = new ParseSourceFile(';;;var', 'in.js'); | 
					
						
							|  |  |  |         const startLocation = new ParseLocation(source, 0, 0, 3); | 
					
						
							|  |  |  |         const endLocation = new ParseLocation(source, 7, 0, 6); | 
					
						
							|  |  |  |         const sourceSpan = new ParseSourceSpan(startLocation, endLocation); | 
					
						
							|  |  |  |         const someVar = o.variable('someVar', null, sourceSpan); | 
					
						
							| 
									
										
										
										
											2017-05-16 16:30:37 -07:00
										 |  |  |         const sm = emitSourceMap(someVar.toStmt(), '/* MyPreamble \n */'); | 
					
						
							| 
									
										
										
										
											2017-01-27 14:23:12 -08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-10-04 13:37:27 -07:00
										 |  |  |         expect(sm.sources).toEqual([someGenFilePath, 'in.js']); | 
					
						
							| 
									
										
										
										
											2017-03-17 09:44:27 -07:00
										 |  |  |         expect(sm.sourcesContent).toEqual([' ', ';;;var']); | 
					
						
							| 
									
										
										
										
											2017-03-15 15:50:30 -07:00
										 |  |  |         expect(originalPositionFor(sm, {line: 3, column: 0})) | 
					
						
							| 
									
										
										
										
											2017-03-14 09:16:15 -07:00
										 |  |  |             .toEqual({line: 1, column: 3, source: 'in.js'}); | 
					
						
							| 
									
										
										
										
											2017-01-27 14:23:12 -08:00
										 |  |  |       }); | 
					
						
							|  |  |  |     }); | 
					
						
							|  |  |  |   }); | 
					
						
							|  |  |  | } |