<commit_before>/*
	MIT License http://www.opensource.org/licenses/mit-license.php
	Author <NAME> @sokra
*/
function FlagDependencyUsagePlugin() {

}
module.exports = FlagDependencyUsagePlugin;

FlagDependencyUsagePlugin.prototype.apply = function(compiler) {
	compiler.plugin("compilation", function(compilation) {
		compilation.plugin("optimize-modules-advanced", function(modules) {

			modules.forEach(function(module) {
				module.used = false;
			});

			var queue = [];
			compilation.chunks.forEach(function(chunk) {
				if(chunk.entryModule) {
					processModule(chunk.entryModule, true);
				}
			});

			while(queue.length) {
				var queueItem = queue.pop();
				processDependenciesBlock(queueItem[0], queueItem[1]);
			}

			function processModule(module, usedExports) {
				module.used = true;
				if(module.usedExports === true)
					return;
				else if(usedExports === true)
					module.usedExports = true;
				else if(Array.isArray(usedExports)) {
					var old = module.usedExports ? module.usedExports.length : -1;
					module.usedExports = addToSet(module.usedExports || [], usedExports);
					if(module.usedExports.length === old)
						return;
				} else if(Array.isArray(module.usedExports))
					return;
				else
					module.usedExports = false;

				queue.push([module, module.usedExports]);
			}

			function processDependenciesBlock(depBlock, usedExports) {
				depBlock.dependencies.forEach(function(dep) {
					processDependency(dep, usedExports);
				});
				depBlock.variables.forEach(function(variable) {
					variable.dependencies.forEach(function(dep) {
						processDependency(dep, usedExports);
					});
				});
				depBlock.blocks.forEach(function(block) {
					queue.push([block, usedExports]);
				});
			}

			function processDependency(dep, usedExports) {
				var reference = dep.getReference && dep.getReference();
				if(!reference) return;
				var module = reference.module;
				var importedNames = reference.importedNames;
				var oldUsed = module.used;
				var oldUsedExports = module.usedExports;
				if(!oldUsed || (importedNames && (!oldUsedExports || !isSubset(oldUsedExports, importedNames)))) {
					processModule(module, importedNames);
				}
			}

		});

		function addToSet(a, b) {
			b.forEach(function(item) {
				if(a.indexOf(item) < 0)
					a.push(item);
			});
			return a;
		}

		function isSubset(biggerSet, subset) {
			if(biggerSet === true) return true;
			if(subset === true) return false;
			return subset.every(function(item) {
				return biggerSet.indexOf(item) >= 0;
			});
		}
	});
};<commit_msg>Refactor(ES6): FlagDependencyUsagePlugin<commit_after>/*
	MIT License http://www.opensource.org/licenses/mit-license.php
	Author <NAME> @sokra
*/
"use strict";

class FlagDependencyUsagePlugin {
	apply(compiler) {
		compiler.plugin("compilation", compilation => {
			compilation.plugin("optimize-modules-advanced", modules => {

				modules.forEach(module => module.used = false);

				const queue = [];
				compilation.chunks.forEach(chunk => {
					if(chunk.entryModule) {
						processModule(chunk.entryModule, true);
					}
				});

				while(queue.length) {
					const queueItem = queue.pop();
					processDependenciesBlock(queueItem[0], queueItem[1]);
				}

				function processModule(module, usedExports) {
					module.used = true;
					if(module.usedExports === true)
						return;
					else if(usedExports === true)
						module.usedExports = true;
					else if(Array.isArray(usedExports)) {
						var old = module.usedExports ? module.usedExports.length : -1;
						module.usedExports = addToSet(module.usedExports || [], usedExports);
						if(module.usedExports.length === old)
							return;
					} else if(Array.isArray(module.usedExports))
						return;
					else
						module.usedExports = false;

					queue.push([module, module.usedExports]);
				}

				function processDependenciesBlock(depBlock, usedExports) {
					depBlock.dependencies.forEach(dep => processDependency(dep, usedExports));
					depBlock.variables.forEach(variable => variable.dependencies.forEach(dep => processDependency(dep, usedExports)));
					depBlock.blocks.forEach(block => queue.push([block, usedExports]));
				}

				function processDependency(dep, usedExports) {
					const reference = dep.getReference && dep.getReference();
					if(!reference) return;
					const module = reference.module;
					const importedNames = reference.importedNames;
					const oldUsed = module.used;
					const oldUsedExports = module.usedExports;
					if(!oldUsed || (importedNames && (!oldUsedExports || !isSubset(oldUsedExports, importedNames)))) {
						processModule(module, importedNames);
					}
				}

			});

			function addToSet(a, b) {
				b.forEach(item => {
					if(a.indexOf(item) < 0)
						a.push(item);
				});
				return a;
			}

			function isSubset(biggerSet, subset) {
				if(biggerSet === true) return true;
				if(subset === true) return false;
				return subset.every(item => biggerSet.indexOf(item) >= 0);
			}
		});
	}
}
module.exports = FlagDependencyUsagePlugin;
{'fraction_non_alphanumeric': 0.13513513513513514, 'fraction_numerical': 0.0021860095389507153, 'mean_word_length': 3.558876811594203, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 17, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5979669', 'n_tokens_mistral': 1966, 'n_tokens_neox': 1523, 'n_words': 265}