<commit_before>//////////////////////////////////////////////////////////////////
// replace `return` with `module.exports`
//////////////////////////////////////////////////////////////////

var UglifyJS = require('uglify-js');
var get_local_nr = require('../neuron/nr-define');

handler = {
    before: function(node, descend){
        var nr_define;

        // may have more than one `return`s
        var local_factory = handler.local_factory;
    
        // must be executed within handler.before
        if(!local_factory){
            if(node.CTOR === UglifyJS.AST_Call){
                nr_define = get_local_nr(node);
                
                if(nr_define){

                    handler.local_factory = nr_define.factory;
                }
            }
        }

        if(node === local_factory){
            descend(node, this);

            // prevent descending again
            return node;
        }

        // prevent descending inner function scope
        // AST_Lambda includes all function declarations, such as
        // - AST_Defun
        // - AST_Accessor
        // - AST_Function
        if(node instanceof UglifyJS.AST_Lambda){
            return node;
        }

        // there might be more than one `return`s<commit_msg>upgrade: tranformer/nr: distinguish global DP and local DP, avoiding naming conflict<commit_after>//////////////////////////////////////////////////////////////////
// replace `return` with `module.exports`
//////////////////////////////////////////////////////////////////

var UglifyJS = require('uglify-js');
var get_local_nr = require('../neuron/nr-define');

var handler = {
    before: function(node, descend){
        var nr_define;

        // may have more than one `return`s
        var local_factory = handler.local_factory;
    
        // must be executed within handler.before
        if(!local_factory){
            nr_define = get_local_nr(node);
                
            if(nr_define){
                handler.local_factory = nr_define.factory;
            }
        }

        if(node === local_factory){
            descend(node, this);
            delete handler.local_factory;

            // prevent descending again
            return node;
        }

        // only walk the AST of the factory function 
        if(!handler.local_factory){
            return;
        }

        // prevent descending inner function scope
        // AST_Lambda includes all function declarations, such as
        // - AST_Defun
        // - AST_Accessor
        // - AST_Function
        if(node instanceof UglifyJS.AST_Lambda){
            return node;
        }

        // there might be more than one `return`s
{'fraction_non_alphanumeric': 0.18188567186340016, 'fraction_numerical': 0.0, 'mean_word_length': 1.2838983050847457, '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': '4639390', 'n_tokens_mistral': 669, 'n_tokens_neox': 632, 'n_words': 170}