| 
									
										
										
										
											2017-11-12 01:48:29 +08:00
										 |  |  | /* | 
					
						
							|  |  |  | 	MIT License http://www.opensource.org/licenses/mit-license.php
 | 
					
						
							|  |  |  | 	Author Tobias Koppers @sokra | 
					
						
							|  |  |  | */ | 
					
						
							|  |  |  | "use strict"; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-12-07 03:37:58 +08:00
										 |  |  | const JsonExportsDependency = require("./dependencies/JsonExportsDependency"); | 
					
						
							| 
									
										
										
										
											2017-11-12 01:48:29 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | class JsonParser { | 
					
						
							|  |  |  | 	constructor(options) { | 
					
						
							|  |  |  | 		this.options = options; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	parse(source, state) { | 
					
						
							| 
									
										
										
										
											2017-12-07 03:37:58 +08:00
										 |  |  | 		const data = JSON.parse(source); | 
					
						
							|  |  |  | 		state.module.buildInfo.jsonData = data; | 
					
						
							|  |  |  | 		state.module.buildMeta.exportsType = "named"; | 
					
						
							| 
									
										
										
										
											2018-02-25 09:00:20 +08:00
										 |  |  | 		if (typeof data === "object" && data) | 
					
						
							| 
									
										
										
										
											2017-12-07 03:37:58 +08:00
										 |  |  | 			state.module.addDependency(new JsonExportsDependency(Object.keys(data))); | 
					
						
							|  |  |  | 		state.module.addDependency(new JsonExportsDependency(["default"])); | 
					
						
							| 
									
										
										
										
											2017-11-12 01:48:29 +08:00
										 |  |  | 		return state; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | module.exports = JsonParser; |