<commit_before>/**
 * @module create
 */
// regex for keyword properties
var keywordRegexp = /^(?:\$\$\w+|bindings|extend|prototype|(?:add|remove)(?:Static|Aliased|Bound)Property)$/,
// regex to test for a mutator name to avoid a loop
mutatorNameTest = /^\$\$(\w+)\$\$/,
// separator for multiple mutator usages
mutatorSeparator = "_",
// reference to existing mutators
namedGlobalMutators = {},
// list of all mutators in the order of definition
globalMutators = [],
// Hook to use Object.defineProperty if needed
objectDefineProperty = function(obj, prop, descriptor) {
	obj[prop] = descriptor;
},
// create the base object that everything extends from
Base = (function() {
	var fn = function() {
	};
	/**
	 * True constructor method for this object, will be called when object is
	 * called with the "new" keyword
	 *
	 * @for Classify.Class
	 * @method init
	 * @return {Class}
	 */
	fn.prototype.init = noop;
	fn.prototype.constructor = fn;
	fn.$$isclass = true;
	return fn;
})(),
/**
 * Internal "Mutator" class that handles hooks for class object manipulation
 *
 * @constructor
 * @for Classify.Mutator
 * @param {String} name The name of the mutator
 * @param {Object} props hash of properties to merge into the prototype
 * @method Mutator
 */
Mutator = function(name, props) {
	if (!(this instanceof Mutator)) {
		return new Mutator(name, props);
	}
	extend(this, props);
	/**
	 * The name of the mutator
	 *
	 * @private
	 * @for Classify.Mutator
	 * @property name
	 * @type {String}
	 */
	this.name = name;
	/**
	 * Flag determining if all property modifications should be run through
	 * this mutator
	 *
	 * @private
	 * @for Classify.Mutator
	 * @property greedy
	 * @type {Boolean}
	 */
	this.greedy = props.greedy === true;
	/**
	 * The property matcher prefix of this mutator
	 *
	 * @private
	 * @for Classify.Mutator
	 * @property propPrefix
	 * @type {RegExp}
	 */
	this.propPrefix = "$$" + name + "$$";
},
// wraps a function so that the "this.$$parent" is bound to the function
wrapParentProperty = function(parentPrototype, property) {
	return store(function() {
		/**
		 * Internal reference property for methods that override a parent
		 * method, allow for access to the parent version of the function.
		 *
		 * @for Classify.Class
		 * @method $$parent
		 * @return {Object}
		 */
		var tmp = this.$$parent, ret;
		this.$$parent = parentPrototype;
		ret = property.apply(this, arguments);
		if (tmp === undefined) {
			delete this.$$parent;
		} else {
			this.$$parent = tmp;
		}
		return ret;
	}, property);
},
/**
 * Adds a global class mutator that modifies the defined classes at different
 * points with hooks
 *
 * @param {String} name The name of the mutator reference to add
 * @param {Object} mutator The mutator definition with optional hooks
 * @param {Function} [mutator._onPredefine] Internal hook to be called as soon
 *            as the constructor is defined
 * @param {Function} [mutator.onCreate] The hook to be called when a class is
 *            defined before any properties are added
 * @param {Function} [mutator.onDefine] The hook to be called when a class is
 *            defined after all properties are added
 * @param {Function} [mutator.onPropAdd] The hook to be called when a property
 *            with the $$name$$ prefix is added
 * @param {Function} [mutator.onPropRemove] The hook to be called when a
 *            property with the $$name$$ prefix is removed
 * @param {Function} [mutator.onInit] The hook to be called during each object's
 *            initialization
 * @param {Function} [mutator.greedy] Attribute to declare that all properties
 *            being added and removed goes through this mutator
 * @throws Error
 * @static
 * @for Classify
 * @method addMutator
 */
addMutator = function(name, mutator) {
	if (namedGlobalMutators[name]) {
		throw new Error("Adding duplicate mutator \"" + name + "\".");
	}
	var mutatorInstance = new Mutator(name, mutator);
	namedGlobalMutators[name] = mutatorInstance;
	globalMutators.push(mutatorInstance);
},
/**
 * Removes a global class mutator that modifies the defined classes at different
 * points
 *
 * @param {String} name The name of the mutator to be removed
 * @throws Error
 * @static
 * @for Classify
 * @method removeMutator
 */
removeMutator = function(name) {
	var mutator = namedGlobalMutators[name];
	if (!mutator) {
		throw new Error("Removing unknown mutator.");
	}
	remove(globalMutators, mutator);
	namedGlobalMutators[name] = null;
	try {
		delete namedGlobalMutators[name];
	} catch (e) {
	}
},
// method to get all possible mutators
getMutators = function(klass) {
	var i, l, mutators = globalMutators.slice(0);
	arrayPush.apply(mutators, klass.$$mutator);
	// hook for namespaces!
	if (klass.getMutators) {
		arrayPush.apply(mutators, klass.getMutators() || []);
	}
	for (i = 0, l = mutators; i < l; i++) {
		if (!(mutators[i] instanceof Mutator)) {
			throw new Error("Mutator objects can only be instances of \"Mutator\", please use createMutator.");
		}
	}
	return mutators;
},
// adds a property to an existing class taking into account parent
addProperty = function(klass, parent, name, property, mutators, isRecurse) {
	var shouldBreak = false, parentPrototype, selfPrototype, mutatatorMatches;
	// we don't want to re-add the core javascript properties, it's redundant
	if (property === objectPrototype[name]) {
		return;
	}

	// extract possible explicit mutators
	mutatatorMatches = mutatorNameTest.exec(name) || [];
	if (mutatatorMatches[1]) {
		// if we passed in `$$mutator$$ : { prop : 1, prop : 2 }`
		if (mutatatorMatches[1] && mutatatorMatches[0] === name && !isRecurse) {
			each(property, function nestedAddPropertyMutatorIterator(prop, key) {
				addProperty(klass, parent, mutatatorMatches[0] + key, prop, mutators, true);
			});
			return;
		}
		// convert explicit mutators to an array
		mutatatorMatches = mutatatorMatches[1].split(mutatorSeparator);
	}
	// replace name to provide for cascade
	name = name.replace(mutatorNameTest, "");
	// check to see if the property needs to be mutated
	each(mutators, function addPropertyMutatorIterator(mutator) {
		if (mutator.onPropAdd && (mutator.greedy || indexOf(mutatatorMatches, mutator.name) > -1)) {
			// use the return value of the mutator as the property to add
			property = mutator.onPropAdd.call(mutator, klass, parent, name, property);
			// if mutator did not return anything, quit
			if (property === undefined) {
				shouldBreak = true;
				return false;
			}
		}
	});
	if (shouldBreak) {
		return;
	}

	// quick references
	parentPrototype = parent.prototype[name];
	selfPrototype = klass.prototype;
	// else this is not a prefixed static property, so we're assigning it to the
	// prototype
	objectDefineProperty(selfPrototype, name, (isFunction(property) && !property.$$isclass && isFunction(parentPrototype)) ? wrapParentProperty(parentPrototype, property) : property);

	// wrap all child implementation with the parent wrapper
	if (isFunction(property)) {
		each(klass.$$subclass, function addSubclassPropertyIterator(k) {
			// add only if it's not already wrapped
			if (isFunction(k.prototype[name]) && !k.prototype[name].$$original) {
				objectDefineProperty(k.prototype, name, wrapParentProperty(selfPrototype[name], k.prototype[name]));
			}
		});<commit_msg>Pass matched mutators to onPropAdd<commit_after>/**
 * @module create
 */
// regex for keyword properties
var keywordRegexp = /^(?:\$\$\w+|bindings|extend|prototype|(?:add|remove)(?:Static|Aliased|Bound)Property)$/,
// regex to test for a mutator name to avoid a loop
mutatorNameTest = /^\$\$(\w+)\$\$/,
// separator for multiple mutator usages
mutatorSeparator = "_",
// reference to existing mutators
namedGlobalMutators = {},
// list of all mutators in the order of definition
globalMutators = [],
// Hook to use Object.defineProperty if needed
objectDefineProperty = function(obj, prop, descriptor) {
	obj[prop] = descriptor;
},
// create the base object that everything extends from
Base = (function() {
	var fn = function() {
	};
	/**
	 * True constructor method for this object, will be called when object is
	 * called with the "new" keyword
	 *
	 * @for Classify.Class
	 * @method init
	 * @return {Class}
	 */
	fn.prototype.init = noop;
	fn.prototype.constructor = fn;
	fn.$$isclass = true;
	return fn;
})(),
/**
 * Internal "Mutator" class that handles hooks for class object manipulation
 *
 * @constructor
 * @for Classify.Mutator
 * @param {String} name The name of the mutator
 * @param {Object} props hash of properties to merge into the prototype
 * @method Mutator
 */
Mutator = function(name, props) {
	if (!(this instanceof Mutator)) {
		return new Mutator(name, props);
	}
	extend(this, props);
	/**
	 * The name of the mutator
	 *
	 * @private
	 * @for Classify.Mutator
	 * @property name
	 * @type {String}
	 */
	this.name = name;
	/**
	 * Flag determining if all property modifications should be run through
	 * this mutator
	 *
	 * @private
	 * @for Classify.Mutator
	 * @property greedy
	 * @type {Boolean}
	 */
	this.greedy = props.greedy === true;
	/**
	 * The property matcher prefix of this mutator
	 *
	 * @private
	 * @for Classify.Mutator
	 * @property propPrefix
	 * @type {RegExp}
	 */
	this.propPrefix = "$$" + name + "$$";
},
// wraps a function so that the "this.$$parent" is bound to the function
wrapParentProperty = function(parentPrototype, property) {
	return store(function() {
		/**
		 * Internal reference property for methods that override a parent
		 * method, allow for access to the parent version of the function.
		 *
		 * @for Classify.Class
		 * @method $$parent
		 * @return {Object}
		 */
		var tmp = this.$$parent, ret;
		this.$$parent = parentPrototype;
		ret = property.apply(this, arguments);
		if (tmp === undefined) {
			delete this.$$parent;
		} else {
			this.$$parent = tmp;
		}
		return ret;
	}, property);
},
/**
 * Adds a global class mutator that modifies the defined classes at different
 * points with hooks
 *
 * @param {String} name The name of the mutator reference to add
 * @param {Object} mutator The mutator definition with optional hooks
 * @param {Function} [mutator._onPredefine] Internal hook to be called as soon
 *            as the constructor is defined
 * @param {Function} [mutator.onCreate] The hook to be called when a class is
 *            defined before any properties are added
 * @param {Function} [mutator.onDefine] The hook to be called when a class is
 *            defined after all properties are added
 * @param {Function} [mutator.onPropAdd] The hook to be called when a property
 *            with the $$name$$ prefix is added
 * @param {Function} [mutator.onPropRemove] The hook to be called when a
 *            property with the $$name$$ prefix is removed
 * @param {Function} [mutator.onInit] The hook to be called during each object's
 *            initialization
 * @param {Function} [mutator.greedy] Attribute to declare that all properties
 *            being added and removed goes through this mutator
 * @throws Error
 * @static
 * @for Classify
 * @method addMutator
 */
addMutator = function(name, mutator) {
	if (namedGlobalMutators[name]) {
		throw new Error("Adding duplicate mutator \"" + name + "\".");
	}
	var mutatorInstance = new Mutator(name, mutator);
	namedGlobalMutators[name] = mutatorInstance;
	globalMutators.push(mutatorInstance);
},
/**
 * Removes a global class mutator that modifies the defined classes at different
 * points
 *
 * @param {String} name The name of the mutator to be removed
 * @throws Error
 * @static
 * @for Classify
 * @method removeMutator
 */
removeMutator = function(name) {
	var mutator = namedGlobalMutators[name];
	if (!mutator) {
		throw new Error("Removing unknown mutator.");
	}
	remove(globalMutators, mutator);
	namedGlobalMutators[name] = null;
	try {
		delete namedGlobalMutators[name];
	} catch (e) {
	}
},
// method to get all possible mutators
getMutators = function(klass) {
	var i, l, mutators = globalMutators.slice(0);
	arrayPush.apply(mutators, klass.$$mutator);
	// hook for namespaces!
	if (klass.getMutators) {
		arrayPush.apply(mutators, klass.getMutators() || []);
	}
	for (i = 0, l = mutators; i < l; i++) {
		if (!(mutators[i] instanceof Mutator)) {
			throw new Error("Mutator objects can only be instances of \"Mutator\", please use createMutator.");
		}
	}
	return mutators;
},
// adds a property to an existing class taking into account parent
addProperty = function(klass, parent, name, property, mutators, isRecurse) {
	var shouldBreak = false, parentPrototype, selfPrototype, mutatatorMatches;
	// we don't want to re-add the core javascript properties, it's redundant
	if (property === objectPrototype[name]) {
		return;
	}

	// extract possible explicit mutators
	mutatatorMatches = mutatorNameTest.exec(name) || [];
	if (mutatatorMatches[1]) {
		// if we passed in `$$mutator$$ : { prop : 1, prop : 2 }`
		if (mutatatorMatches[1] && mutatatorMatches[0] === name && !isRecurse) {
			each(property, function nestedAddPropertyMutatorIterator(prop, key) {
				addProperty(klass, parent, mutatatorMatches[0] + key, prop, mutators, true);
			});
			return;
		}
		// convert explicit mutators to an array
		mutatatorMatches = mutatatorMatches[1].split(mutatorSeparator);
	}
	// replace name to provide for cascade
	name = name.replace(mutatorNameTest, "");
	// check to see if the property needs to be mutated
	each(mutators, function addPropertyMutatorIterator(mutator) {
		if (mutator.onPropAdd && (mutator.greedy || indexOf(mutatatorMatches, mutator.name) > -1)) {
			// use the return value of the mutator as the property to add
			property = mutator.onPropAdd.call(mutator, klass, parent, name, property, mutatatorMatches);
			// if mutator did not return anything, quit
			if (property === undefined) {
				shouldBreak = true;
				return false;
			}
		}
	});
	if (shouldBreak) {
		return;
	}

	// quick references
	parentPrototype = parent.prototype[name];
	selfPrototype = klass.prototype;
	// else this is not a prefixed static property, so we're assigning it to the
	// prototype
	objectDefineProperty(selfPrototype, name, (isFunction(property) && !property.$$isclass && isFunction(parentPrototype)) ? wrapParentProperty(parentPrototype, property) : property);

	// wrap all child implementation with the parent wrapper
	if (isFunction(property)) {
		each(klass.$$subclass, function addSubclassPropertyIterator(k) {
			// add only if it's not already wrapped
			if (isFunction(k.prototype[name]) && !k.prototype[name].$$original) {
				objectDefineProperty(k.prototype, name, wrapParentProperty(selfPrototype[name], k.prototype[name]));
			}
		});
{'fraction_non_alphanumeric': 0.12065551382724479, 'fraction_numerical': 0.0013656538067599864, 'mean_word_length': 3.8690159574468086, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, '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': '2586358', 'n_tokens_mistral': 4586, 'n_tokens_neox': 4327, 'n_words': 1479}