| 
									
										
										
										
											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"); | 
					
						
							| 
									
										
										
										
											2016-02-04 06:40:41 +08:00
										 |  |  | var Template = require("./Template"); | 
					
						
							| 
									
										
										
										
											2013-01-31 01:49:25 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | var debugId = 1000; | 
					
						
							| 
									
										
										
										
											2015-07-13 06:20:09 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-01-31 01:49:25 +08:00
										 |  |  | 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; | 
					
						
							| 
									
										
										
										
											2016-10-05 00:15:54 +08:00
										 |  |  | 	this.portableId = null; | 
					
						
							| 
									
										
										
										
											2015-06-13 17:52:29 +08:00
										 |  |  | 	this.index = null; | 
					
						
							|  |  |  | 	this.index2 = null; | 
					
						
							| 
									
										
										
										
											2016-12-14 19:03:24 +08:00
										 |  |  | 	this.depth = null; | 
					
						
							| 
									
										
										
										
											2015-10-22 03:05:01 +08:00
										 |  |  | 	this.used = null; | 
					
						
							|  |  |  | 	this.usedExports = null; | 
					
						
							| 
									
										
										
										
											2016-09-06 05:41:03 +08:00
										 |  |  | 	this.providedExports = null; | 
					
						
							| 
									
										
										
										
											2013-01-31 01:49:25 +08:00
										 |  |  | 	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 = []; | 
					
						
							| 
									
										
										
										
											2016-05-05 23:45:58 +08:00
										 |  |  | 	this.strict = false; | 
					
						
							| 
									
										
										
										
											2016-07-03 19:13:01 +08:00
										 |  |  | 	this.meta = {}; | 
					
						
							| 
									
										
										
										
											2013-01-31 01:49:25 +08:00
										 |  |  | } | 
					
						
							|  |  |  | module.exports = Module; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | Module.prototype = Object.create(DependenciesBlock.prototype); | 
					
						
							| 
									
										
										
										
											2015-10-22 03:05:01 +08:00
										 |  |  | Module.prototype.constructor = Module; | 
					
						
							| 
									
										
										
										
											2013-01-31 01:49:25 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-07-13 17:03:14 +08:00
										 |  |  | Object.defineProperty(Module.prototype, "entry", { | 
					
						
							|  |  |  | 	configurable: false, | 
					
						
							|  |  |  | 	get: function() { | 
					
						
							|  |  |  | 		throw new Error("Module.entry was removed. Use Chunk.entryModule"); | 
					
						
							|  |  |  | 	}, | 
					
						
							|  |  |  | 	set: function() { | 
					
						
							|  |  |  | 		throw new Error("Module.entry was removed. Use Chunk.entryModule"); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | }); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-01-31 01:49:25 +08:00
										 |  |  | 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; | 
					
						
							| 
									
										
										
										
											2015-06-13 17:52:29 +08:00
										 |  |  | 	this.index = null; | 
					
						
							|  |  |  | 	this.index2 = null; | 
					
						
							| 
									
										
										
										
											2016-12-14 19:03:24 +08:00
										 |  |  | 	this.depth = null; | 
					
						
							| 
									
										
										
										
											2015-10-22 03:05:01 +08:00
										 |  |  | 	this.used = null; | 
					
						
							|  |  |  | 	this.usedExports = null; | 
					
						
							| 
									
										
										
										
											2016-09-06 05:41:03 +08:00
										 |  |  | 	this.providedExports = null; | 
					
						
							| 
									
										
										
										
											2013-01-31 01:49:25 +08:00
										 |  |  | 	this.chunks.length = 0; | 
					
						
							|  |  |  | 	DependenciesBlock.prototype.disconnect.call(this); | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-07-13 17:03:14 +08:00
										 |  |  | Module.prototype.unseal = function() { | 
					
						
							|  |  |  | 	this.lastId = this.id; | 
					
						
							|  |  |  | 	this.id = null; | 
					
						
							|  |  |  | 	this.index = null; | 
					
						
							|  |  |  | 	this.index2 = null; | 
					
						
							| 
									
										
										
										
											2016-12-14 19:03:24 +08:00
										 |  |  | 	this.depth = null; | 
					
						
							| 
									
										
										
										
											2016-07-13 17:03:14 +08:00
										 |  |  | 	this.chunks.length = 0; | 
					
						
							|  |  |  | 	DependenciesBlock.prototype.unseal.call(this); | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-01-31 01:49:25 +08:00
										 |  |  | Module.prototype.addChunk = function(chunk) { | 
					
						
							|  |  |  | 	var idx = this.chunks.indexOf(chunk); | 
					
						
							| 
									
										
										
										
											2015-07-16 06:19:23 +08:00
										 |  |  | 	if(idx < 0) | 
					
						
							| 
									
										
										
										
											2013-01-31 01:49:25 +08:00
										 |  |  | 		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) { | 
					
						
							| 
									
										
										
										
											2015-07-16 06:19:23 +08:00
										 |  |  | 	for(var i = 0; i < this.reasons.length; i++) { | 
					
						
							| 
									
										
										
										
											2014-07-19 20:32:48 +08:00
										 |  |  | 		var r = this.reasons[i]; | 
					
						
							| 
									
										
										
										
											2015-07-16 06:19:23 +08:00
										 |  |  | 		if(r.module === module && r.dependency === dependency) { | 
					
						
							| 
									
										
										
										
											2014-07-19 20:32:48 +08:00
										 |  |  | 			this.reasons.splice(i, 1); | 
					
						
							|  |  |  | 			return true; | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	return false; | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | Module.prototype.hasReasonForChunk = function(chunk) { | 
					
						
							| 
									
										
										
										
											2015-07-16 06:19:23 +08:00
										 |  |  | 	for(var i = 0; i < this.reasons.length; i++) { | 
					
						
							| 
									
										
										
										
											2014-07-19 20:32:48 +08:00
										 |  |  | 		var r = this.reasons[i]; | 
					
						
							| 
									
										
										
										
											2015-07-16 06:19:23 +08:00
										 |  |  | 		if(r.chunks) { | 
					
						
							|  |  |  | 			if(r.chunks.indexOf(chunk) >= 0) | 
					
						
							| 
									
										
										
										
											2014-09-08 04:54:38 +08:00
										 |  |  | 				return true; | 
					
						
							| 
									
										
										
										
											2015-07-16 06:19:23 +08:00
										 |  |  | 		} 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) { | 
					
						
							| 
									
										
										
										
											2015-07-16 06:19:23 +08:00
										 |  |  | 		if(set.indexOf(item) < 0) | 
					
						
							| 
									
										
										
										
											2014-09-08 04:54:38 +08:00
										 |  |  | 			set.push(item); | 
					
						
							|  |  |  | 	}); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | Module.prototype.rewriteChunkInReasons = function(oldChunk, newChunks) { | 
					
						
							|  |  |  | 	this.reasons.forEach(function(r) { | 
					
						
							| 
									
										
										
										
											2015-07-16 06:19:23 +08:00
										 |  |  | 		if(!r.chunks) { | 
					
						
							|  |  |  | 			if(r.module.chunks.indexOf(oldChunk) < 0) | 
					
						
							| 
									
										
										
										
											2014-09-08 04:54:38 +08:00
										 |  |  | 				return; | 
					
						
							|  |  |  | 			r.chunks = r.module.chunks; | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 		r.chunks = r.chunks.reduce(function(arr, c) { | 
					
						
							|  |  |  | 			addToSet(arr, c !== oldChunk ? [c] : newChunks); | 
					
						
							|  |  |  | 			return arr; | 
					
						
							|  |  |  | 		}, []); | 
					
						
							|  |  |  | 	}); | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-10-22 03:05:01 +08:00
										 |  |  | Module.prototype.isUsed = function(exportName) { | 
					
						
							| 
									
										
										
										
											2016-02-04 06:40:41 +08:00
										 |  |  | 	if(this.used === null) return exportName; | 
					
						
							|  |  |  | 	if(!exportName) return this.used ? true : false; | 
					
						
							| 
									
										
										
										
											2015-10-22 03:05:01 +08:00
										 |  |  | 	if(!this.used) return false; | 
					
						
							|  |  |  | 	if(!this.usedExports) return false; | 
					
						
							| 
									
										
										
										
											2016-02-04 06:40:41 +08:00
										 |  |  | 	if(this.usedExports === true) return exportName; | 
					
						
							|  |  |  | 	var idx = this.usedExports.indexOf(exportName); | 
					
						
							|  |  |  | 	if(idx < 0) return false; | 
					
						
							| 
									
										
										
										
											2016-09-07 15:44:53 +08:00
										 |  |  | 	if(this.isProvided(exportName)) | 
					
						
							| 
									
										
										
										
											2016-02-04 06:40:41 +08:00
										 |  |  | 		return Template.numberToIdentifer(idx); | 
					
						
							|  |  |  | 	return exportName; | 
					
						
							|  |  |  | }; | 
					
						
							| 
									
										
										
										
											2015-10-22 03:05:01 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-09-06 05:41:03 +08:00
										 |  |  | Module.prototype.isProvided = function(exportName) { | 
					
						
							|  |  |  | 	if(!Array.isArray(this.providedExports)) | 
					
						
							|  |  |  | 		return null; | 
					
						
							|  |  |  | 	return this.providedExports.indexOf(exportName) >= 0; | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-01-31 01:49:25 +08:00
										 |  |  | Module.prototype.toString = function() { | 
					
						
							|  |  |  | 	return "Module[" + (this.id || this.debugId) + "]"; | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-12-30 00:10:41 +08:00
										 |  |  | Module.prototype.needRebuild = function(fileTimestamps, contextTimestamps) { | 
					
						
							| 
									
										
										
										
											2013-01-31 01:49:25 +08:00
										 |  |  | 	return true; | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-05-17 06:31:52 +08:00
										 |  |  | Module.prototype.updateHash = function(hash) { | 
					
						
							| 
									
										
										
										
											2015-10-22 03:05:01 +08:00
										 |  |  | 	hash.update(this.id + "" + this.used); | 
					
						
							| 
									
										
										
										
											2016-02-04 07:06:16 +08:00
										 |  |  | 	hash.update(JSON.stringify(this.usedExports)); | 
					
						
							| 
									
										
										
										
											2014-05-17 06:31:52 +08:00
										 |  |  | 	DependenciesBlock.prototype.updateHash.call(this, hash); | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-07-13 17:03:14 +08:00
										 |  |  | function byId(a, b) { | 
					
						
							|  |  |  | 	return a.id - b.id; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | Module.prototype.sortItems = function() { | 
					
						
							|  |  |  | 	DependenciesBlock.prototype.sortItems.call(this); | 
					
						
							|  |  |  | 	this.chunks.sort(byId); | 
					
						
							|  |  |  | 	this.reasons.sort(function(a, b) { | 
					
						
							|  |  |  | 		return byId(a.module, b.module); | 
					
						
							|  |  |  | 	}); | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-12-05 06:47:19 +08:00
										 |  |  | Module.prototype.unbuild = function() { | 
					
						
							|  |  |  | 	this.disconnect(); | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											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; | 
					
						
							| 
									
										
										
										
											2016-09-14 18:04:42 +08:00
										 |  |  | Module.prototype.nameForCondition = null; |