Code coverage report for lib\optimize\RemoveParentModulesPlugin.js

Statements: 100% (26 / 26)      Branches: 100% (12 / 12)      Functions: 100% (9 / 9)      Lines: 100% (21 / 21)      Ignored: none     

All files » lib\optimize\ » RemoveParentModulesPlugin.js
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41        1 767 626 113 129       1 732 732 767 767   130     1   1   1 484 496 496 877 3130 619 106                
/*
	MIT License http://www.opensource.org/licenses/mit-license.php
	Author Tobias Koppers @sokra
*/
function hasModule(chunk, module, checkedChunks) {
	if(chunk.modules.indexOf(module) >= 0) return true;
	if(chunk.entry) return false;
	return allHaveModule(chunk.parents.filter(function(c) {
		return checkedChunks.indexOf(c) < 0;
	}), module, checkedChunks);
}
 
function allHaveModule(someChunks, module, checkedChunks) {
	if(!checkedChunks) checkedChunks = [];
	for(var i = 0; i < someChunks.length; i++) {
		checkedChunks.push(someChunks[i]);
		if(!hasModule(someChunks[i], module, checkedChunks)) return false;
	}
	return true;
}
 
function RemoveParentModulesPlugin() {
}
module.exports = RemoveParentModulesPlugin;
 
RemoveParentModulesPlugin.prototype.apply = function(compiler) {
	compiler.plugin("compilation", function(compilation) {
		compilation.plugin("optimize-chunks", function(chunks) {
			chunks.forEach(function(chunk) {
				chunk.modules.slice().forEach(function(module) {
					if(chunk.entry) return;
					if(allHaveModule(chunk.parents, module)) {
						chunk.removeModule(module);
					}
				});
			});
		});
	});
};