| 
									
										
										
										
											2016-07-13 17:03:14 +08:00
										 |  |  | /* | 
					
						
							|  |  |  | 	MIT License http://www.opensource.org/licenses/mit-license.php
 | 
					
						
							|  |  |  | 	Author Tobias Koppers @sokra | 
					
						
							|  |  |  | */ | 
					
						
							| 
									
										
										
										
											2017-01-24 14:55:39 +08:00
										 |  |  | "use strict"; | 
					
						
							| 
									
										
										
										
											2018-05-20 15:16:33 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-06-25 16:43:59 +08:00
										 |  |  | /** @typedef {import("./Dependency").DependencyLocation} DependencyLocation */ | 
					
						
							| 
									
										
										
										
											2018-05-20 15:16:33 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | /** | 
					
						
							|  |  |  |  * Compare two locations | 
					
						
							| 
									
										
										
										
											2018-07-06 16:52:50 +08:00
										 |  |  |  * @param {DependencyLocation} a A location node | 
					
						
							|  |  |  |  * @param {DependencyLocation} b A location node | 
					
						
							| 
									
										
										
										
											2018-05-20 15:18:20 +08:00
										 |  |  |  * @returns {-1|0|1} sorting comparator value | 
					
						
							| 
									
										
										
										
											2018-05-20 15:16:33 +08:00
										 |  |  |  */ | 
					
						
							| 
									
										
										
										
											2017-11-08 18:32:05 +08:00
										 |  |  | module.exports = (a, b) => { | 
					
						
							| 
									
										
										
										
											2018-07-09 14:57:09 +08:00
										 |  |  | 	let isObjectA = typeof a === "object" && a !== null; | 
					
						
							|  |  |  | 	let isObjectB = typeof b === "object" && b !== null; | 
					
						
							|  |  |  | 	if (!isObjectA || !isObjectB) { | 
					
						
							|  |  |  | 		if (isObjectA) return 1; | 
					
						
							|  |  |  | 		if (isObjectB) return -1; | 
					
						
							| 
									
										
										
										
											2018-07-06 16:52:50 +08:00
										 |  |  | 		return 0; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	if ("start" in a && "start" in b) { | 
					
						
							|  |  |  | 		const ap = a.start; | 
					
						
							|  |  |  | 		const bp = b.start; | 
					
						
							|  |  |  | 		if (ap.line < bp.line) return -1; | 
					
						
							|  |  |  | 		if (ap.line > bp.line) return 1; | 
					
						
							|  |  |  | 		if (ap.column < bp.column) return -1; | 
					
						
							|  |  |  | 		if (ap.column > bp.column) return 1; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	if ("name" in a && "name" in b) { | 
					
						
							|  |  |  | 		if (a.name < b.name) return -1; | 
					
						
							|  |  |  | 		if (a.name > b.name) return 1; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	if ("index" in a && "index" in b) { | 
					
						
							|  |  |  | 		if (a.index < b.index) return -1; | 
					
						
							|  |  |  | 		if (a.index > b.index) return 1; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	return 0; | 
					
						
							| 
									
										
										
										
											2016-07-13 17:03:14 +08:00
										 |  |  | }; |