<commit_before>
(function () {
    
    var Proteus  = require("proteus"),
        FS       = require("fs"),
        uglylib  = require("uglify-js"),
        template = require("underscore").template,
        Infuser  = require("./infuser"),
        Iterator = require("./iterator"),
        jsp      = uglylib.parser,
        jsb      = uglylib.uglify,
        infuseTmpl,
        fnTmpl, strTmpl
    ;
    
    //-----------------------------------------------------------------------
    // Templates
    //-----------------------------------------------------------------------
    infuseTmpl = FS.readFileSync(__dirname + "/infuse-src.js", "utf8");
    
    fnTmpl = template([
        "\"<%=key%>\": function () {",
            "var module  = __infuse__.modules[<%=key%>], exports = module.exports;",
            "<%=code%>",
            "__infuse__.clear(<%=key%>);",
        "}"
    ].join("\n"));
    
    strTmpl = template("\"<%=key%>\": \"<%=code%>\"");
    
    //-----------------------------------------------------------------------
    // Exports
    //-----------------------------------------------------------------------
    function infuse (src, opts) {
        var infuser, ast, infuserAst, modCode, modAst, iter;
        
        infuser = new Infuser({
            definitions: opts.definitions,
            reserved:    opts.reserved,
            libPaths:    opts.libPaths
        });
        
        ast = infuser.infuse(src).getAst();
        
        // generate our main template AST
        infuserAst = jsp.parse(infuseTmpl);
        // generate our modules AST
        modCode = "__infuse__.modules = {" + 
            infuser.infusions.items.map(function (infusion, id) {
                var code = infusion.getCode(!opts.nominify);  

                if (opts.embed) {
                    code = code.replace(/\"/g, "\\\"");
                }

                return (opts.embed ? strTmpl : fnTmpl)({
                    key: id,
                    code: code
                });
            }).join(",\n") + "};";
        
        modAst = jsp.parse(modCode);

        // determine where to insert our module AST
        iter = new Iterator(infuserAst);
        iter.skipTo("function");
        iter.getCurrent()[3].push(modAst[1][0]);

        // Update the final AST with the infuser AST
        ast[1] = infuserAst[1].concat(ast[1]);

        if (!opts.nominify) {
            ast = jsb.ast_lift_variables(ast);
            ast = jsb.ast_mangle(ast, {
                except: opts.reserved
            });
            ast = jsb.ast_squeeze(ast, {
                make_seqs: false,
                dead_code: true
            });<commit_msg>Only add the infuse stub-code if there are modules actually included.<commit_after>
(function () {
    
    var Proteus  = require("proteus"),
        FS       = require("fs"),
        uglylib  = require("uglify-js"),
        template = require("underscore").template,
        Infuser  = require("./infuser"),
        Iterator = require("./iterator"),
        jsp      = uglylib.parser,
        jsb      = uglylib.uglify,
        infuseTmpl,
        fnTmpl, strTmpl
    ;
    
    //-----------------------------------------------------------------------
    // Templates
    //-----------------------------------------------------------------------
    infuseTmpl = FS.readFileSync(__dirname + "/infuse-src.js", "utf8");
    
    fnTmpl = template([
        "\"<%=key%>\": function () {",
            "var module  = __infuse__.modules[<%=key%>], exports = module.exports;",
            "<%=code%>",
            "__infuse__.clear(<%=key%>);",
        "}"
    ].join("\n"));
    
    strTmpl = template("\"<%=key%>\": \"<%=code%>\"");
    
    //-----------------------------------------------------------------------
    // Exports
    //-----------------------------------------------------------------------
    function infuse (src, opts) {
        var infuser, infusions, ast, infuserAst, modCode, modAst, iter;
        
        infuser = new Infuser({
            definitions: opts.definitions,
            reserved:    opts.reserved,
            libPaths:    opts.libPaths
        });
        
        ast = infuser.infuse(src).getAst();
        
        infusions = infuser.infusions.items;
        if (infusions.length) {
            // generate our main template AST
            infuserAst = jsp.parse(infuseTmpl);
            // generate our modules AST
            modCode = "__infuse__.modules = {" + 
                infusions.map(function (infusion, id) {
                    var code = infusion.getCode(!opts.nominify);  

                    if (opts.embed) {
                        code = code.replace(/\"/g, "\\\"");
                    }

                    return (opts.embed ? strTmpl : fnTmpl)({
                        key: id,
                        code: code
                    });
                }).join(",\n") + "};";

            modAst = jsp.parse(modCode);

            // determine where to insert our module AST
            iter = new Iterator(infuserAst);
            iter.skipTo("function");
            iter.getCurrent()[3].push(modAst[1][0]);

            // Update the final AST with the infuser AST
            ast[1] = infuserAst[1].concat(ast[1]);
        }

        if (!opts.nominify) {
            ast = jsb.ast_lift_variables(ast);
            ast = jsb.ast_mangle(ast, {
                except: opts.reserved
            });
            ast = jsb.ast_squeeze(ast, {
                make_seqs: false,
                dead_code: true
            });
{'fraction_non_alphanumeric': 0.23333333333333334, 'fraction_numerical': 0.0025089605734767025, 'mean_word_length': 1.1092214663643236, 'pattern_counts': {'":': 4, '<': 15, '<?xml version=': 0, '>': 15, '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': '6291360', 'n_tokens_mistral': 1571, 'n_tokens_neox': 1471, 'n_words': 285}