| 
									
										
										
										
											2013-01-31 01:49:25 +08:00
										 |  |  | /* | 
					
						
							|  |  |  | 	MIT License http://www.opensource.org/licenses/mit-license.php
 | 
					
						
							|  |  |  | 	Author Tobias Koppers @sokra | 
					
						
							|  |  |  | */ | 
					
						
							|  |  |  | var DependenciesBlock = require("./DependenciesBlock"); | 
					
						
							|  |  |  | var ModuleReason = require("./ModuleReason"); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | var debugId = 1000; | 
					
						
							|  |  |  | function Module() { | 
					
						
							|  |  |  | 	DependenciesBlock.call(this); | 
					
						
							|  |  |  | 	this.context = null; | 
					
						
							|  |  |  | 	this.reasons = []; | 
					
						
							|  |  |  | 	this.debugId = debugId++; | 
					
						
							| 
									
										
										
										
											2013-05-08 19:28:54 +08:00
										 |  |  | 	this.lastId = -1; | 
					
						
							| 
									
										
										
										
											2013-01-31 01:49:25 +08:00
										 |  |  | 	this.id = null; | 
					
						
							|  |  |  | 	this.chunks = []; | 
					
						
							|  |  |  | 	this.warnings = []; | 
					
						
							| 
									
										
										
										
											2013-05-18 20:42:11 +08:00
										 |  |  | 	this.dependenciesWarnings = []; | 
					
						
							| 
									
										
										
										
											2013-01-31 01:49:25 +08:00
										 |  |  | 	this.errors = []; | 
					
						
							| 
									
										
										
										
											2013-05-18 20:42:11 +08:00
										 |  |  | 	this.dependenciesErrors = []; | 
					
						
							| 
									
										
										
										
											2013-01-31 01:49:25 +08:00
										 |  |  | } | 
					
						
							|  |  |  | module.exports = Module; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | Module.prototype = Object.create(DependenciesBlock.prototype); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | Module.prototype.disconnect = function() { | 
					
						
							|  |  |  | 	this.reasons.length = 0; | 
					
						
							| 
									
										
										
										
											2013-05-08 19:28:54 +08:00
										 |  |  | 	this.lastId = this.id; | 
					
						
							| 
									
										
										
										
											2013-01-31 01:49:25 +08:00
										 |  |  | 	this.id = null; | 
					
						
							|  |  |  | 	this.chunks.length = 0; | 
					
						
							|  |  |  | 	DependenciesBlock.prototype.disconnect.call(this); | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | Module.prototype.addChunk = function(chunk) { | 
					
						
							|  |  |  | 	var idx = this.chunks.indexOf(chunk); | 
					
						
							|  |  |  | 	if(idx < 0) | 
					
						
							|  |  |  | 		this.chunks.push(chunk); | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-06-25 00:53:32 +08:00
										 |  |  | Module.prototype._removeAndDo = require("./removeAndDo"); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-01-31 01:49:25 +08:00
										 |  |  | Module.prototype.removeChunk = function(chunk) { | 
					
						
							| 
									
										
										
										
											2014-07-19 20:32:48 +08:00
										 |  |  | 	return this._removeAndDo("chunks", chunk, "removeModule"); | 
					
						
							| 
									
										
										
										
											2013-01-31 01:49:25 +08:00
										 |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | Module.prototype.addReason = function(module, dependency) { | 
					
						
							|  |  |  | 	this.reasons.push(new ModuleReason(module, dependency)); | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-07-19 20:32:48 +08:00
										 |  |  | Module.prototype.removeReason = function(module, dependency) { | 
					
						
							|  |  |  | 	for(var i = 0; i < this.reasons.length; i++) { | 
					
						
							|  |  |  | 		var r = this.reasons[i]; | 
					
						
							|  |  |  | 		if(r.module === module && r.dependency === dependency) { | 
					
						
							|  |  |  | 			this.reasons.splice(i, 1); | 
					
						
							|  |  |  | 			return true; | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	return false; | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | Module.prototype.hasReasonForChunk = function(chunk) { | 
					
						
							|  |  |  | 	for(var i = 0; i < this.reasons.length; i++) { | 
					
						
							|  |  |  | 		var r = this.reasons[i]; | 
					
						
							| 
									
										
										
										
											2014-09-08 04:54:38 +08:00
										 |  |  | 		if(r.chunks) { | 
					
						
							|  |  |  | 			if(r.chunks.indexOf(chunk) >= 0) | 
					
						
							|  |  |  | 				return true; | 
					
						
							|  |  |  | 		} else if(r.module.chunks.indexOf(chunk) >= 0) | 
					
						
							| 
									
										
										
										
											2014-07-19 20:32:48 +08:00
										 |  |  | 			return true; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	return false; | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-09-08 04:54:38 +08:00
										 |  |  | function addToSet(set, items) { | 
					
						
							|  |  |  | 	items.forEach(function(item) { | 
					
						
							|  |  |  | 		if(set.indexOf(item) < 0) | 
					
						
							|  |  |  | 			set.push(item); | 
					
						
							|  |  |  | 	}); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | Module.prototype.rewriteChunkInReasons = function(oldChunk, newChunks) { | 
					
						
							|  |  |  | 	this.reasons.forEach(function(r) { | 
					
						
							|  |  |  | 		if(!r.chunks) { | 
					
						
							|  |  |  | 			if(r.module.chunks.indexOf(oldChunk) < 0) | 
					
						
							|  |  |  | 				return; | 
					
						
							|  |  |  | 			r.chunks = r.module.chunks; | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 		r.chunks = r.chunks.reduce(function(arr, c) { | 
					
						
							|  |  |  | 			addToSet(arr, c !== oldChunk ? [c] : newChunks); | 
					
						
							|  |  |  | 			return arr; | 
					
						
							|  |  |  | 		}, []); | 
					
						
							|  |  |  | 	}); | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-01-31 01:49:25 +08:00
										 |  |  | Module.prototype.toString = function() { | 
					
						
							|  |  |  | 	return "Module[" + (this.id || this.debugId) + "]"; | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | Module.prototype.needRebuild = function(fileTimestamps, contextTimestamps) { | 
					
						
							|  |  |  | 	return true; | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-05-17 06:31:52 +08:00
										 |  |  | Module.prototype.updateHash = function(hash) { | 
					
						
							|  |  |  | 	hash.update(this.id + ""); | 
					
						
							|  |  |  | 	DependenciesBlock.prototype.updateHash.call(this, hash); | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-01-31 01:49:25 +08:00
										 |  |  | Module.prototype.identifier = null; | 
					
						
							|  |  |  | Module.prototype.readableIdentifier = null; | 
					
						
							|  |  |  | Module.prototype.build = null; | 
					
						
							|  |  |  | Module.prototype.source = null; | 
					
						
							|  |  |  | Module.prototype.size = null; |