mirror of https://github.com/webpack/webpack.git
				
				
				
			refactor AsyncDependenciesBlock to es6 syntax
This commit is contained in:
		
							parent
							
								
									0607fc1127
								
							
						
					
					
						commit
						2c32b087c8
					
				|  | @ -2,61 +2,55 @@ | ||||||
| 	MIT License http://www.opensource.org/licenses/mit-license.php
 | 	MIT License http://www.opensource.org/licenses/mit-license.php
 | ||||||
| 	Author Tobias Koppers @sokra | 	Author Tobias Koppers @sokra | ||||||
| */ | */ | ||||||
| var DependenciesBlock = require("./DependenciesBlock"); | "use strict"; | ||||||
|  | const DependenciesBlock = require("./DependenciesBlock"); | ||||||
| 
 | 
 | ||||||
| function AsyncDependenciesBlock(name, module, loc) { | module.exports = class AsyncDependenciesBlock extends DependenciesBlock { | ||||||
| 	DependenciesBlock.call(this); | 	constructor(name, module, loc) { | ||||||
| 	this.chunkName = name; | 		super(); | ||||||
| 	this.chunks = null; | 		this.chunkName = name; | ||||||
| 	this.module = module; | 		this.chunks = null; | ||||||
| 	this.loc = loc; | 		this.module = module; | ||||||
|  | 		this.loc = loc; | ||||||
| 
 | 
 | ||||||
| 	Object.defineProperty(this, "chunk", { | 		Object.defineProperty(this, "chunk", { | ||||||
| 		get: function() { | 			get: function() { | ||||||
| 			throw new Error("`chunk` was been renamed to `chunks` and is now an array"); | 				throw new Error("`chunk` was been renamed to `chunks` and is now an array"); | ||||||
| 		}, | 			}, | ||||||
| 		set: function() { | 			set: function() { | ||||||
| 			throw new Error("`chunk` was been renamed to `chunks` and is now an array"); | 				throw new Error("`chunk` was been renamed to `chunks` and is now an array"); | ||||||
| 		} |  | ||||||
| 	}); |  | ||||||
| 
 |  | ||||||
| } |  | ||||||
| module.exports = AsyncDependenciesBlock; |  | ||||||
| 
 |  | ||||||
| AsyncDependenciesBlock.prototype = Object.create(DependenciesBlock.prototype); |  | ||||||
| AsyncDependenciesBlock.prototype.constructor = AsyncDependenciesBlock; |  | ||||||
| 
 |  | ||||||
| AsyncDependenciesBlock.prototype.updateHash = function updateHash(hash) { |  | ||||||
| 	hash.update(this.chunkName || ""); |  | ||||||
| 	hash.update(this.chunks && this.chunks.map(function(chunk) { |  | ||||||
| 		return typeof chunk.id === "number" ? chunk.id : ""; |  | ||||||
| 	}).join(",") || ""); |  | ||||||
| 	DependenciesBlock.prototype.updateHash.call(this, hash); |  | ||||||
| }; |  | ||||||
| 
 |  | ||||||
| AsyncDependenciesBlock.prototype.disconnect = function() { |  | ||||||
| 	this.chunks = null; |  | ||||||
| 	DependenciesBlock.prototype.disconnect.call(this); |  | ||||||
| }; |  | ||||||
| 
 |  | ||||||
| AsyncDependenciesBlock.prototype.unseal = function() { |  | ||||||
| 	this.chunks = null; |  | ||||||
| 	DependenciesBlock.prototype.unseal.call(this); |  | ||||||
| }; |  | ||||||
| 
 |  | ||||||
| AsyncDependenciesBlock.prototype.sortItems = function() { |  | ||||||
| 	DependenciesBlock.prototype.sortItems.call(this); |  | ||||||
| 	if(this.chunks) { |  | ||||||
| 		this.chunks.sort(function(a, b) { |  | ||||||
| 			var i = 0; |  | ||||||
| 			while(true) { // eslint-disable-line no-constant-condition
 |  | ||||||
| 				if(!a.modules[i] && !b.modules[i]) return 0; |  | ||||||
| 				if(!a.modules[i]) return -1; |  | ||||||
| 				if(!b.modules[i]) return 1; |  | ||||||
| 				if(a.modules[i].id > b.modules[i].id) return 1; |  | ||||||
| 				if(a.modules[i].id < b.modules[i].id) return -1; |  | ||||||
| 				i++; |  | ||||||
| 			} | 			} | ||||||
| 		}); | 		}); | ||||||
| 	} | 	} | ||||||
| }; | 	updateHash(hash) { | ||||||
|  | 		hash.update(this.chunkName || ""); | ||||||
|  | 		hash.update(this.chunks && this.chunks.map((chunk) => { | ||||||
|  | 			return typeof chunk.id === "number" ? chunk.id : ""; | ||||||
|  | 		}).join(",").replace(/,\s*$/, "") || ""); | ||||||
|  | 		super.updateHash(hash); | ||||||
|  | 	} | ||||||
|  | 	disconnect() { | ||||||
|  | 		this.chunks = null; | ||||||
|  | 		super.disconnect(); | ||||||
|  | 	} | ||||||
|  | 	unseal() { | ||||||
|  | 		this.chunks = null; | ||||||
|  | 		super.unseal(); | ||||||
|  | 	} | ||||||
|  | 	sortItems() { | ||||||
|  | 		super.sortItems(); | ||||||
|  | 		if(this.chunks) { | ||||||
|  | 			this.chunks.sort((a, b) => { | ||||||
|  | 				let i = 0; | ||||||
|  | 				while(true) { // eslint-disable-line no-constant-condition
 | ||||||
|  | 					if(!a.modules[i] && !b.modules[i]) return 0; | ||||||
|  | 					if(!a.modules[i]) return -1; | ||||||
|  | 					if(!b.modules[i]) return 1; | ||||||
|  | 					if(a.modules[i].id > b.modules[i].id) return 1; | ||||||
|  | 					if(a.modules[i].id < b.modules[i].id) return -1; | ||||||
|  | 					i++; | ||||||
|  | 				} | ||||||
|  | 			}); | ||||||
|  | 		} | ||||||
|  | 	} | ||||||
|  | } | ||||||
|  |  | ||||||
		Loading…
	
		Reference in New Issue