<commit_before>'use strict';

function addExportFactory(
    coordsHelper,
    editActionsFactory,
    logger,
    parser,
    selectionExportHelper,
    selectionExpressionHelper,
    templateHelper,
    utilities,
    vsCodeFactory) {

    return function (_, callback) {

        function getSelectionEditorCoords(activeEditor) {
            const firstSelectionCoords = utilities.getAllSelectionCoords(activeEditor)[0];
            return coordsHelper.coordsFromDocumentToEditor(firstSelectionCoords);
        }

        function exportSelectedNode(activeEditor, astNode, ast) {
            const editActions = editActionsFactory(activeEditor);
            
            const exportName = astNode.id.name;

            const exportNode = selectionExportHelper.getExportNode(ast);

            let exportLocation = exportNode !== null
                ? coordsHelper.coordsFromAstToEditor(exportNode.loc).end
                : coordsHelper.coordsFromAstToEditor(ast.loc).end;

            let exportTemplateKey;

            if(exportNode === null) {
                exportTemplateKey = 'newExport';
                exportLocation = coordsHelper.coordsFromAstToEditor(ast.loc).end;
            } else if(selectionExportHelper.isMultilineExport(exportNode.expression.left, exportNode.expression.right)) {
                exportTemplateKey = 'mulitilineExport';
                exportLocation = coordsHelper.coordsFromAstToEditor(exportNode.expression.right.loc).start;
                exportLocation[1] += 1;
            } else {
                exportTemplateKey = 'oneLineExport';
                exportLocation = coordsHelper.coordsFromAstToEditor(exportNode.loc).end;
            }

            const exportEditorCoords = {
                start: exportLocation,
                end: exportLocation
            };

            const exportContext = {
                name: exportName
            };

            const exportStr = templateHelper.templates[exportTemplateKey].build(exportContext);

            editActions.applySetEdit(exportStr, exportEditorCoords, function () {
                callback();
            });
        }

        return function () {
            const activeEditor = vsCodeFactory.get().window.activeTextEditor;
            const selectionEditorCoords = getSelectionEditorCoords(activeEditor);
            const selectionAstCoords = coordsHelper.coordsFromEditorToAst(selectionEditorCoords);

            const sourceLines = utilities.getDocumentLines(activeEditor);
            const ast = parser.parseSourceLines(sourceLines);

            const selectedExportValue = selectionExpressionHelper.getNearestFunctionOrVariable(selectionAstCoords, ast);

            if(selectedExportValue === null) {
                logger.info('Cannot export a value which is not a function or variable declaration.');
                callback();
            } else {
                exportSelectedNode(activeEditor, selectedExportValue, ast);
            }

        }
    };
}<commit_msg>Rolled back change to test behavior<commit_after>'use strict';

function addExportFactory(
    coordsHelper,
    editActionsFactory,
    logger,
    parser,
    selectionExportHelper,
    selectionExpressionHelper,
    templateHelper,
    utilities,
    vsCodeFactory) {

    return function (_, callback) {

        function getSelectionEditorCoords(activeEditor) {
            const firstSelectionCoords = utilities.getAllSelectionCoords(activeEditor)[0];
            return coordsHelper.coordsFromDocumentToEditor(firstSelectionCoords);
        }

        function exportSelectedNode(activeEditor, astNode, ast) {
            const editActions = editActionsFactory(activeEditor);
            
            const exportName = astNode.id.name;

            const exportNode = selectionExportHelper.getExportNode(ast);

            let exportLocation = exportNode !== null
                ? coordsHelper.coordsFromAstToEditor(exportNode.loc).end
                : coordsHelper.coordsFromAstToEditor(ast.loc).end;

            let exportTemplateKey;

            if(exportNode === null) {
                exportTemplateKey = 'newExport';
                exportLocation = coordsHelper.coordsFromAstToEditor(ast.loc).end;
            } else if(selectionExportHelper.isMultilineExport(exportNode.expression.left, exportNode.expression.right)) {
                exportTemplateKey = 'mulitilineExport';
                exportLocation = coordsHelper.coordsFromAstToEditor(exportNode.expression.right.loc).start;
                exportLocation[1] += 1;
            } else {
                exportTemplateKey = 'oneLineExport';
                exportLocation = coordsHelper.coordsFromAstToEditor(exportNode.loc).end;
            }

            const exportEditorCoords = {
                start: exportLocation,
                end: exportLocation
            };

            const exportContext = {
                name: exportName
            };

            const exportStr = templateHelper.templates[exportTemplateKey].build(exportContext);

            editActions.applySetEdit(exportStr, exportEditorCoords, function () {
                callback();
            });
        }

        return function () {
            const activeEditor = vsCodeFactory.get().window.activeTextEditor;
            const selectionEditorCoords = getSelectionEditorCoords(activeEditor);
            const selectionAstCoords = coordsHelper.coordsFromEditorToAst(selectionEditorCoords);

            const sourceLines = utilities.getDocumentLines(activeEditor);
            const ast = parser.parseSourceLines(sourceLines);

            const selectedExportValue = selectionExpressionHelper.getNearestFunctionOrVariable(selectionAstCoords, ast);

            if(selectedExportValue === null) {
                logger.info('Cannot export a value which is not a function or variable declaration.');
                callback();
            } else {
                exportSelectedNode(activeEditor, selectedExportValue, ast);
            }

        }
    };
}

module.exports = addExportFactory;
{'fraction_non_alphanumeric': 0.07627677100494235, 'fraction_numerical': 0.0009884678747940692, 'mean_word_length': 2.2940857297883883, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '1064531', 'n_tokens_mistral': 1481, 'n_tokens_neox': 1391, 'n_words': 249}