<commit_before>/*
	MIT License http://www.opensource.org/licenses/mit-license.php
	Author <NAME> @sokra
*/
"use strict";

const Module = require("../Module");
const Template = require("../Template");
const Parser = require("../Parser");
const acorn = require("acorn");
const escope = require("escope");
const ReplaceSource = require("webpack-sources/lib/ReplaceSource");
const ConcatSource = require("webpack-sources/lib/ConcatSource");
const HarmonyImportDependency = require("../dependencies/HarmonyImportDependency");
const HarmonyImportSpecifierDependency = require("../dependencies/HarmonyImportSpecifierDependency");
const HarmonyExportSpecifierDependency = require("../dependencies/HarmonyExportSpecifierDependency");
const HarmonyExportExpressionDependency = require("../dependencies/HarmonyExportExpressionDependency");
const HarmonyExportImportedSpecifierDependency = require("../dependencies/HarmonyExportImportedSpecifierDependency");
const HarmonyCompatibilityDependency = require("../dependencies/HarmonyCompatibilityDependency");
const HarmonyModulesHelpers = require("../dependencies/HarmonyModulesHelpers");

function getFinalName(info, exportName, moduleToInfoMap, requestShortener) {
	const directExport = info.exportMap.get(exportName);
	if(directExport) {
		if(exportName === true)
			info.needNamespaceObject = true;
		return info.internalNames.get(directExport);
	}
	const reexport = info.reexportMap.get(exportName);
	if(reexport) {
		const refInfo = moduleToInfoMap.get(reexport.module);
		if(refInfo) {
			// module is in the concatenation
			return getFinalName(refInfo, reexport.exportName, moduleToInfoMap, requestShortener);
		} else {
			const dep = reexport.dependency;
			const importedModule = reexport.module;
			const exportName = reexport.exportName;
			const isHarmonyModule = importedModule && (!importedModule.meta || importedModule.meta.harmonyModule);
			const importedVar = dep.importedVar;
			const used = importedModule.isUsed(exportName);
			if(!used) return "/* unused reexport */undefined";
			if(!isHarmonyModule && exportName === "default") {
				return `${importedVar}_default.a`;
			}
			return `${importedVar}[${JSON.stringify(used)}]`;
		}
	}
	throw new Error(`Cannot get final name for export "${exportName}" in "${info.module.readableIdentifier(requestShortener)}"` +
		` (known exports: ${Array.from(info.exportMap.keys()).join(" ")}, ` +
		`known reexports: ${Array.from(info.reexportMap.keys()).join(" ")})`);
}

function getSymbolsFromScope(s, untilScope) {
	const allUsedNames = new Set();
	let scope = s;
	while(scope) {
		if(untilScope === scope) break;
		scope.variables.forEach(variable => allUsedNames.add(variable.name));
		scope = scope.upper;
	}
	return allUsedNames;
}

function getAllReferences(variable) {
	let set = variable.references;
	// Look for inner scope variables too (like in class Foo { t() { Foo } })
	const identifiers = new Set(variable.identifiers);
	for(const scope of variable.scope.childScopes) {
		for(const innerVar of scope.variables) {
			if(innerVar.identifiers.some(id => identifiers.has(id))) {
				set = set.concat(innerVar.references);
				break;
			}
		}
	}
	return set;
}

function reduceSet(a, b) {
	for(const item of b)
		a.add(item);
	return a;
}

function getPathInAst(ast, node) {
	if(ast === node) {
		return [];
	}
	const nr = node.range;
	var i;
	if(Array.isArray(ast)) {
		for(i = 0; i < ast.length; i++) {
			const enterResult = enterNode(ast[i]);
			if(typeof enterResult !== "undefined")
				return enterResult;
		}
	} else if(ast && typeof ast === "object") {
		const keys = Object.keys(ast);
		for(i = 0; i < keys.length; i++) {
			const value = ast[keys[i]];
			if(Array.isArray(value)) {
				const pathResult = getPathInAst(value, node);
				if(typeof pathResult !== "undefined")
					return pathResult;
			} else if(value && typeof value === "object") {
				const enterResult = enterNode(value);
				if(typeof enterResult !== "undefined")
					return enterResult;
			}
		}
	}

	function enterNode(n) {
		const r = n.range;
		if(r) {
			if(r[0] <= nr[0] && r[1] >= nr[1]) {
				const path = getPathInAst(n, node);
				if(path) {
					path.push(n);
					return path;
				}
			}
		}
		return undefined;
	}
}

class ConcatenatedModule extends Module {
	constructor(rootModule, modules) {
		super();
		this.rootModule = rootModule;
		this.modules = modules;
		this.usedExports = rootModule.usedExports;
		this.providedExports = rootModule.providedExports;
		this.optimizationBailout = rootModule.optimizationBailout;
		this.used = rootModule.used;
		this._chunks = new Set(rootModule._chunks);
		this.index = rootModule.index;
		this.index2 = rootModule.index2;
		this.depth = rootModule.depth;
		this.built = modules.some(m => m.built);
		this.cacheable = modules.every(m => m.cacheable);
		const modulesSet = new Set(modules);
		this.reasons = rootModule.reasons.filter(reason => !modulesSet.has(reason.module));
		this.dependencies = [].concat.apply([], modules.map(m => m.dependencies.filter(dep => !modulesSet.has(dep.module))));
		this.meta = rootModule.meta;
		this.dependenciesWarnings = modules.reduce((w, m) => m.dependenciesWarnings.forEach(x => w.push(x)), []);
		this.dependenciesErrors = modules.reduce((w, m) => m.dependenciesErrors.forEach(x => w.push(x)), []);
		this.warnings = modules.reduce((w, m) => m.warnings.forEach(x => w.push(x)), []);
		this.errors = modules.reduce((w, m) => m.errors.forEach(x => w.push(x)), []);
		this.moduleArgument = rootModule.moduleArgument;
		this.exportsArgument = rootModule.exportsArgument;
		this.strict = true;
		modules.forEach((m, idx) => {
			for(const dep of m.dependencies.filter(dep => !modulesSet.has(dep.module))) {<commit_msg>remove code that pushes arrays of dependencies into dependencies<commit_after>/*
	MIT License http://www.opensource.org/licenses/mit-license.php
	Author <NAME> @sokra
*/
"use strict";

const Module = require("../Module");
const Template = require("../Template");
const Parser = require("../Parser");
const acorn = require("acorn");
const escope = require("escope");
const ReplaceSource = require("webpack-sources/lib/ReplaceSource");
const ConcatSource = require("webpack-sources/lib/ConcatSource");
const HarmonyImportDependency = require("../dependencies/HarmonyImportDependency");
const HarmonyImportSpecifierDependency = require("../dependencies/HarmonyImportSpecifierDependency");
const HarmonyExportSpecifierDependency = require("../dependencies/HarmonyExportSpecifierDependency");
const HarmonyExportExpressionDependency = require("../dependencies/HarmonyExportExpressionDependency");
const HarmonyExportImportedSpecifierDependency = require("../dependencies/HarmonyExportImportedSpecifierDependency");
const HarmonyCompatibilityDependency = require("../dependencies/HarmonyCompatibilityDependency");
const HarmonyModulesHelpers = require("../dependencies/HarmonyModulesHelpers");

function getFinalName(info, exportName, moduleToInfoMap, requestShortener) {
	const directExport = info.exportMap.get(exportName);
	if(directExport) {
		if(exportName === true)
			info.needNamespaceObject = true;
		return info.internalNames.get(directExport);
	}
	const reexport = info.reexportMap.get(exportName);
	if(reexport) {
		const refInfo = moduleToInfoMap.get(reexport.module);
		if(refInfo) {
			// module is in the concatenation
			return getFinalName(refInfo, reexport.exportName, moduleToInfoMap, requestShortener);
		} else {
			const dep = reexport.dependency;
			const importedModule = reexport.module;
			const exportName = reexport.exportName;
			const isHarmonyModule = importedModule && (!importedModule.meta || importedModule.meta.harmonyModule);
			const importedVar = dep.importedVar;
			const used = importedModule.isUsed(exportName);
			if(!used) return "/* unused reexport */undefined";
			if(!isHarmonyModule && exportName === "default") {
				return `${importedVar}_default.a`;
			}
			return `${importedVar}[${JSON.stringify(used)}]`;
		}
	}
	throw new Error(`Cannot get final name for export "${exportName}" in "${info.module.readableIdentifier(requestShortener)}"` +
		` (known exports: ${Array.from(info.exportMap.keys()).join(" ")}, ` +
		`known reexports: ${Array.from(info.reexportMap.keys()).join(" ")})`);
}

function getSymbolsFromScope(s, untilScope) {
	const allUsedNames = new Set();
	let scope = s;
	while(scope) {
		if(untilScope === scope) break;
		scope.variables.forEach(variable => allUsedNames.add(variable.name));
		scope = scope.upper;
	}
	return allUsedNames;
}

function getAllReferences(variable) {
	let set = variable.references;
	// Look for inner scope variables too (like in class Foo { t() { Foo } })
	const identifiers = new Set(variable.identifiers);
	for(const scope of variable.scope.childScopes) {
		for(const innerVar of scope.variables) {
			if(innerVar.identifiers.some(id => identifiers.has(id))) {
				set = set.concat(innerVar.references);
				break;
			}
		}
	}
	return set;
}

function reduceSet(a, b) {
	for(const item of b)
		a.add(item);
	return a;
}

function getPathInAst(ast, node) {
	if(ast === node) {
		return [];
	}
	const nr = node.range;
	var i;
	if(Array.isArray(ast)) {
		for(i = 0; i < ast.length; i++) {
			const enterResult = enterNode(ast[i]);
			if(typeof enterResult !== "undefined")
				return enterResult;
		}
	} else if(ast && typeof ast === "object") {
		const keys = Object.keys(ast);
		for(i = 0; i < keys.length; i++) {
			const value = ast[keys[i]];
			if(Array.isArray(value)) {
				const pathResult = getPathInAst(value, node);
				if(typeof pathResult !== "undefined")
					return pathResult;
			} else if(value && typeof value === "object") {
				const enterResult = enterNode(value);
				if(typeof enterResult !== "undefined")
					return enterResult;
			}
		}
	}

	function enterNode(n) {
		const r = n.range;
		if(r) {
			if(r[0] <= nr[0] && r[1] >= nr[1]) {
				const path = getPathInAst(n, node);
				if(path) {
					path.push(n);
					return path;
				}
			}
		}
		return undefined;
	}
}

class ConcatenatedModule extends Module {
	constructor(rootModule, modules) {
		super();
		this.rootModule = rootModule;
		this.modules = modules;
		this.usedExports = rootModule.usedExports;
		this.providedExports = rootModule.providedExports;
		this.optimizationBailout = rootModule.optimizationBailout;
		this.used = rootModule.used;
		this._chunks = new Set(rootModule._chunks);
		this.index = rootModule.index;
		this.index2 = rootModule.index2;
		this.depth = rootModule.depth;
		this.built = modules.some(m => m.built);
		this.cacheable = modules.every(m => m.cacheable);
		const modulesSet = new Set(modules);
		this.reasons = rootModule.reasons.filter(reason => !modulesSet.has(reason.module));
		this.dependencies = [];
		this.meta = rootModule.meta;
		this.dependenciesWarnings = modules.reduce((w, m) => m.dependenciesWarnings.forEach(x => w.push(x)), []);
		this.dependenciesErrors = modules.reduce((w, m) => m.dependenciesErrors.forEach(x => w.push(x)), []);
		this.warnings = modules.reduce((w, m) => m.warnings.forEach(x => w.push(x)), []);
		this.errors = modules.reduce((w, m) => m.errors.forEach(x => w.push(x)), []);
		this.moduleArgument = rootModule.moduleArgument;
		this.exportsArgument = rootModule.exportsArgument;
		this.strict = true;
		modules.forEach((m, idx) => {
			for(const dep of m.dependencies.filter(dep => !modulesSet.has(dep.module))) {
{'fraction_non_alphanumeric': 0.14858801794668777, 'fraction_numerical': 0.0014075833553268233, 'mean_word_length': 4.738515901060071, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 39, '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': '3609752', 'n_tokens_mistral': 3908, 'n_tokens_neox': 3573, 'n_words': 734}