| 
									
										
										
										
											2016-09-06 05:41:03 +08:00
										 |  |  | /* | 
					
						
							|  |  |  | 	MIT License http://www.opensource.org/licenses/mit-license.php
 | 
					
						
							|  |  |  | 	Author Tobias Koppers @sokra | 
					
						
							|  |  |  | */ | 
					
						
							|  |  |  | function FlagDependencyExportsPlugin() { | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | module.exports = FlagDependencyExportsPlugin; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | FlagDependencyExportsPlugin.prototype.apply = function(compiler) { | 
					
						
							|  |  |  | 	compiler.plugin("compilation", function(compilation) { | 
					
						
							| 
									
										
										
										
											2016-09-07 15:44:53 +08:00
										 |  |  | 		compilation.plugin("finish-modules", function(modules) { | 
					
						
							| 
									
										
										
										
											2016-09-06 05:41:03 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | 			var dependencies = {}; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 			var module, moduleWithExports; | 
					
						
							| 
									
										
										
										
											2016-09-07 15:44:53 +08:00
										 |  |  | 			var queue = modules.filter(function(m) { | 
					
						
							|  |  |  | 				return !m.providedExports; | 
					
						
							|  |  |  | 			}); | 
					
						
							| 
									
										
										
										
											2016-09-06 05:41:03 +08:00
										 |  |  | 			for(var i = 0; i < queue.length; i++) { | 
					
						
							|  |  |  | 				module = queue[i]; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 				if(module.providedExports !== true) { | 
					
						
							|  |  |  | 					moduleWithExports = false; | 
					
						
							|  |  |  | 					processDependenciesBlock(module); | 
					
						
							|  |  |  | 					if(!moduleWithExports) { | 
					
						
							|  |  |  | 						module.providedExports = true; | 
					
						
							| 
									
										
										
										
											2016-09-09 20:50:14 +08:00
										 |  |  | 						notifyDependencies(); | 
					
						
							| 
									
										
										
										
											2016-09-06 05:41:03 +08:00
										 |  |  | 					} | 
					
						
							|  |  |  | 				} | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 			function processDependenciesBlock(depBlock) { | 
					
						
							|  |  |  | 				depBlock.dependencies.forEach(function(dep) { | 
					
						
							|  |  |  | 					processDependency(dep); | 
					
						
							|  |  |  | 				}); | 
					
						
							|  |  |  | 				depBlock.variables.forEach(function(variable) { | 
					
						
							|  |  |  | 					variable.dependencies.forEach(function(dep) { | 
					
						
							|  |  |  | 						processDependency(dep); | 
					
						
							|  |  |  | 					}); | 
					
						
							|  |  |  | 				}); | 
					
						
							|  |  |  | 				depBlock.blocks.forEach(function(block) { | 
					
						
							|  |  |  | 					processDependenciesBlock(block); | 
					
						
							|  |  |  | 				}); | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 			function processDependency(dep, usedExports) { | 
					
						
							|  |  |  | 				var exportDesc = dep.getExports && dep.getExports(); | 
					
						
							|  |  |  | 				if(!exportDesc) return; | 
					
						
							|  |  |  | 				moduleWithExports = true; | 
					
						
							|  |  |  | 				var exports = exportDesc.exports; | 
					
						
							|  |  |  | 				var exportDeps = exportDesc.dependencies; | 
					
						
							|  |  |  | 				if(exportDeps) { | 
					
						
							|  |  |  | 					exportDeps.forEach(function(dep) { | 
					
						
							|  |  |  | 						var depIdent = dep.identifier(); | 
					
						
							|  |  |  | 						var array = dependencies["$" + depIdent]; | 
					
						
							|  |  |  | 						if(!array) array = dependencies["$" + depIdent] = []; | 
					
						
							|  |  |  | 						if(array.indexOf(module) < 0) | 
					
						
							|  |  |  | 							array.push(module); | 
					
						
							|  |  |  | 					}); | 
					
						
							|  |  |  | 				} | 
					
						
							|  |  |  | 				var changed = false; | 
					
						
							| 
									
										
										
										
											2016-09-09 20:20:29 +08:00
										 |  |  | 				if(module.providedExports !== true) { | 
					
						
							|  |  |  | 					if(exports === true) { | 
					
						
							|  |  |  | 						module.providedExports = true; | 
					
						
							| 
									
										
										
										
											2016-09-06 05:41:03 +08:00
										 |  |  | 						changed = true; | 
					
						
							| 
									
										
										
										
											2016-09-09 20:20:29 +08:00
										 |  |  | 					} else if(Array.isArray(exports)) { | 
					
						
							|  |  |  | 						if(Array.isArray(module.providedExports)) { | 
					
						
							|  |  |  | 							changed = addToSet(module.providedExports, exports); | 
					
						
							|  |  |  | 						} else { | 
					
						
							|  |  |  | 							module.providedExports = exports.slice(); | 
					
						
							|  |  |  | 							changed = true; | 
					
						
							|  |  |  | 						} | 
					
						
							| 
									
										
										
										
											2016-11-21 08:00:25 +08:00
										 |  |  | 					} | 
					
						
							| 
									
										
										
										
											2016-09-09 20:20:29 +08:00
										 |  |  | 				} | 
					
						
							| 
									
										
										
										
											2016-09-06 05:41:03 +08:00
										 |  |  | 				if(changed) { | 
					
						
							| 
									
										
										
										
											2016-09-09 20:50:14 +08:00
										 |  |  | 					notifyDependencies(); | 
					
						
							|  |  |  | 				} | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 			function notifyDependencies() { | 
					
						
							|  |  |  | 				var deps = dependencies["$" + module.identifier()]; | 
					
						
							|  |  |  | 				if(deps) { | 
					
						
							|  |  |  | 					deps.forEach(function(dep) { | 
					
						
							|  |  |  | 						queue.push(dep); | 
					
						
							|  |  |  | 					}); | 
					
						
							| 
									
										
										
										
											2016-09-06 05:41:03 +08:00
										 |  |  | 				} | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 		}); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		function addToSet(a, b) { | 
					
						
							|  |  |  | 			var changed = false; | 
					
						
							|  |  |  | 			b.forEach(function(item) { | 
					
						
							|  |  |  | 				if(a.indexOf(item) < 0) { | 
					
						
							|  |  |  | 					a.push(item); | 
					
						
							|  |  |  | 					changed = true; | 
					
						
							|  |  |  | 				} | 
					
						
							|  |  |  | 			}); | 
					
						
							|  |  |  | 			return changed; | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 	}); | 
					
						
							|  |  |  | }; |