<commit_before>import replacePath from "../helpers/replacePath";

const membToString = (t, {object, property, computed}) => {
	const propIsIdentifier = t.isIdentifier(property);
	if(!object.name || (computed && propIsIdentifier)) return null;
	return object.name + "." + (propIsIdentifier ? property.name : property.value);
};

const replaceRequire = (t, replacementObj, pathToReplace) => {
	if(pathToReplace.parentPath.isMemberExpression({object: pathToReplace.node})) {
		replacementObj = t.parenthesizedExpression(replacementObj);
	}
	
	pathToReplace.replaceWith(replacementObj);
};

export default function (t, path, state, calculatedOpts) {
	const {callee} = path.node, {functionNames} = calculatedOpts;
	if((t.isIdentifier(callee) && functionNames.has(callee.name)) ||
		t.isImport(callee) ||
		(t.isMemberExpression(callee) && functionNames.has(membToString(t, callee)))
	) {
		<commit_msg>refactor(transformers): Shortcircuit before calling memToString when possible<commit_after>import replacePath from "../helpers/replacePath";

const membToString = (t, {object, property, computed}) => {
	const propIsIdentifier = t.isIdentifier(property);
	if(!object.name || (computed && propIsIdentifier)) return null;
	return object.name + "." + (propIsIdentifier ? property.name : property.value);
};

const replaceRequire = (t, replacementObj, pathToReplace) => {
	if(pathToReplace.parentPath.isMemberExpression({object: pathToReplace.node})) {
		replacementObj = t.parenthesizedExpression(replacementObj);
	}
	
	pathToReplace.replaceWith(replacementObj);
};

export default function (t, path, state, calculatedOpts) {
	const {callee} = path.node, {functionNames} = calculatedOpts;
	if((t.isIdentifier(callee) && functionNames.has(callee.name)) ||
		t.isImport(callee) ||
		// don't check further if there is only "require" in functionNames
		(functionNames.size > 1 && t.isMemberExpression(callee) && functionNames.has(membToString(t, callee)))
	) {
		
{'fraction_non_alphanumeric': 0.141321044546851, 'fraction_numerical': 0.0005120327700972862, 'mean_word_length': 6.157509157509158, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 8, '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': '6415676', 'n_tokens_mistral': 606, 'n_tokens_neox': 590, 'n_words': 120}