<commit_before>function BH() {
    this._lastGenId = 0;
    this._lastMatchId = 0;
    this._matchers = [];
    this._dirtyEnv = false;
    for (var i in {}) {
        this._dirtyEnv = true;
        break;
    }
    this._selfCloseHtmlTags = {
        area: 1,
        base: 1,
        br: 1,
        col: 1,
        command: 1,
        embed: 1,
        hr: 1,
        img: 1,
        input: 1,
        keygen: 1,
        link: 1,
        meta: 1,
        param: 1,
        source: 1,
        wbr: 1
    };
    /**
     * External libs namespace.
     * @type {Object}
     */
    this.lib = {};
    this.utils = {
        bh: this,
        extend: function(target) {
            typeof target !== 'object' && (target = {});
            for(var i = 1, len = arguments.length; i < len; i++) {
                var obj = arguments[i];
                if(obj) {
                    for(var key in obj) {
                        obj.hasOwnProperty(key) && (target[key] = obj[key]);
                    }
                }
            }
            return target;
        },
        isArray: function (obj) {
            return Array.isArray(obj);
        },
        position: function () {
            var node = this.node;
            return node.index === 'content' ? 0 : node.index;
        },
        isFirst: function () {
            var node = this.node;
            return node.index === 'content' || node.index === 0;
        },
        isLast: function () {
            var node = this.node;
            return node.index === 'content' ? true : node.index === node.arr.length - 1;
        },
        tParam: function (key, value) {
            var keyName = <KEY>;
            if (arguments.length === 2) {
                this.node[keyName] = value;
            } else {
                var node = this.node;
                while (node) {
                    if (node.hasOwnProperty(keyName)) {
                        return node[keyName];
                    }
                    node = node.parentNode;
                }
            }
        },
        apply: function (bemjson) {
            return this.bh.processBemjson(bemjson);
        }
    };
}

BH.prototype = {

    /**
     * Converts BEMJSON to HTML code.
     * @param {Object|Array|String} bemjson
     */
    apply: function (bemjson) {
        return this.toHtml(this.processBemjson(bemjson));
    },

    /**
     * Declares matcher.
     * @example
     *
     *      bh.match('b-page', function(ctx) {
     *          ctx.mix.push({ block: 'i-ua' });
     *          ctx.cls = ctx.cls || 'i-ua_js_no i-ua_css_standard';
     *      });
     *
     *      bh.match('block_mod_modVal', function(ctx) {
     *          ctx.tag = ctx.tag || 'span';
     *      });
     *
     *      bh.match('block__elem', function(ctx) {
     *          ctx.attrs.disabled = 'disabled';
     *      });
     *
     *      bh.match('block__elem_elemMod_elemModVal', function(ctx) {
     *          ctx.mods.active = ctx.mods.active || 'yes';
     *      });
     *
     *      bh.match('block_blockMod_blockModVal__elem', function(ctx) {
     *          ctx.content = {
     *              elem: 'wrapper',
     *              content: ctx
     *          };
     *      });
     *
     * @param {String} expr
     * @param {Function} matcher
     */
    match: function (expr, matcher) {
        matcher.__id = '__func' + (this._lastMatchId++);
        this._matchers.push([expr, matcher]);
    },

    generateId: function () {
        return 'uniq' + (this._lastGenId++);
    },

    buildMatcher: function () {
        var i;
        var res = ['(function() {'];
        var vars = ['ms = this._matchers', 'bh = this'];
        var allMatchers = this._matchers;
        var currentBlock;
        var prevExpr;
        for (i = allMatchers.length - 1; i >= 0; i--) {
            vars.push('_m' + i + ' = ms[' + i + '][1]');
        }
        res.push('var ' + vars.join(', ') + ';');
        res.push('function applyMatchers(ctx) {');
        res.push('var subRes;');
        for (i = allMatchers.length - 1; i >= 0; i--) {
            var mi = allMatchers[i];
            var expr = mi[0];
            var decl = {};
            var exprBits;
            var blockExprBits;
            var jsCond = '';
            if (expr) {
                if (~expr.indexOf('__')) {
                    exprBits = expr.split('__');
                    blockExprBits = exprBits[0].split('_');
                    decl.block = blockExprBits[0];
                    if (blockExprBits.length > 1) {
                        decl.blockMod = blockExprBits[1];
                        decl.blockModVal = blockExprBits[2];
                    }
                    exprBits = exprBits[1].split('_');
                    decl.elem = exprBits[0];
                    if (exprBits.length > 1) {
                        decl.mod = exprBits[1];
                        decl.modVal = exprBits[2];
                    }
                } else {
                    exprBits = expr.split('_');
                    decl.block = exprBits[0];
                    if (exprBits.length > 1) {
                        decl.mod = exprBits[1];
                        decl.modVal = exprBits[2];
                    }
                }
            }
            if (currentBlock !== decl.block) {
                if (currentBlock) {
                    res.push('}');
                }
                currentBlock = decl.block;
                if (currentBlock) {
                    res.push('if (ctx.block === "' + currentBlock + '") {');
                }
            }
            var conds = [];
            decl.elem && conds.push('ctx.elem === "' + decl.elem + '"');
            decl.block && !decl.elem && conds.push('!ctx.elem');
            decl.mod && conds.push('ctx.mods.' + decl.mod + ' === "' + decl.modVal + '"');
            if (decl.block && decl.blockMod) {
                conds.push('ctx.blockMods.' + decl.blockMod + ' === "' + decl.blockModVal + '"');
            }
            jsCond && conds.push(jsCond);
            conds.push('!ctx.' + mi[1].__id);
            res.push('if (' + conds.join(' && ') + ') {');
            res.push('ctx.' + mi[1].__id + ' = true;');
            var strFn = mi[1].toString();
            if (~strFn.indexOf('attrs')) {
                res.push('ctx.attrs = ctx.attrs || {};');
            }
            if (~strFn.indexOf('mods')) {
                res.push('ctx.mods = ctx.mods || {};');
            }
            if (~strFn.indexOf('mix')) {
                res.push('ctx.mix = ctx.mix || [];');<commit_msg>mods fix<commit_after>function BH() {
    this._lastGenId = 0;
    this._lastMatchId = 0;
    this._matchers = [];
    this._dirtyEnv = false;
    for (var i in {}) {
        this._dirtyEnv = true;
        break;
    }
    this._selfCloseHtmlTags = {
        area: 1,
        base: 1,
        br: 1,
        col: 1,
        command: 1,
        embed: 1,
        hr: 1,
        img: 1,
        input: 1,
        keygen: 1,
        link: 1,
        meta: 1,
        param: 1,
        source: 1,
        wbr: 1
    };
    /**
     * External libs namespace.
     * @type {Object}
     */
    this.lib = {};
    this.utils = {
        bh: this,
        extend: function(target) {
            typeof target !== 'object' && (target = {});
            for(var i = 1, len = arguments.length; i < len; i++) {
                var obj = arguments[i];
                if(obj) {
                    for(var key in obj) {
                        obj.hasOwnProperty(key) && (target[key] = obj[key]);
                    }
                }
            }
            return target;
        },
        isArray: function (obj) {
            return Array.isArray(obj);
        },
        position: function () {
            var node = this.node;
            return node.index === 'content' ? 0 : node.index;
        },
        isFirst: function () {
            var node = this.node;
            return node.index === 'content' || node.index === 0;
        },
        isLast: function () {
            var node = this.node;
            return node.index === 'content' ? true : node.index === node.arr.length - 1;
        },
        tParam: function (key, value) {
            var keyName = '__tp_' + key;
            if (arguments.length === 2) {
                this.node[keyName] = value;
            } else {
                var node = this.node;
                while (node) {
                    if (node.hasOwnProperty(keyName)) {
                        return node[keyName];
                    }
                    node = node.parentNode;
                }
            }
        },
        apply: function (bemjson) {
            return this.bh.processBemjson(bemjson);
        }
    };
}

BH.prototype = {

    /**
     * Converts BEMJSON to HTML code.
     * @param {Object|Array|String} bemjson
     */
    apply: function (bemjson) {
        return this.toHtml(this.processBemjson(bemjson));
    },

    /**
     * Declares matcher.
     * @example
     *
     *      bh.match('b-page', function(ctx) {
     *          ctx.mix.push({ block: 'i-ua' });
     *          ctx.cls = ctx.cls || 'i-ua_js_no i-ua_css_standard';
     *      });
     *
     *      bh.match('block_mod_modVal', function(ctx) {
     *          ctx.tag = ctx.tag || 'span';
     *      });
     *
     *      bh.match('block__elem', function(ctx) {
     *          ctx.attrs.disabled = 'disabled';
     *      });
     *
     *      bh.match('block__elem_elemMod_elemModVal', function(ctx) {
     *          ctx.mods.active = ctx.mods.active || 'yes';
     *      });
     *
     *      bh.match('block_blockMod_blockModVal__elem', function(ctx) {
     *          ctx.content = {
     *              elem: 'wrapper',
     *              content: ctx
     *          };
     *      });
     *
     * @param {String} expr
     * @param {Function} matcher
     */
    match: function (expr, matcher) {
        matcher.__id = '__func' + (this._lastMatchId++);
        this._matchers.push([expr, matcher]);
    },

    generateId: function () {
        return 'uniq' + (this._lastGenId++);
    },

    buildMatcher: function () {
        var i;
        var res = ['(function() {'];
        var vars = ['ms = this._matchers', 'bh = this'];
        var allMatchers = this._matchers;
        var currentBlock;
        var prevExpr;
        for (i = allMatchers.length - 1; i >= 0; i--) {
            vars.push('_m' + i + ' = ms[' + i + '][1]');
        }
        res.push('var ' + vars.join(', ') + ';');
        res.push('function applyMatchers(ctx) {');
        res.push('var subRes;');
        for (i = allMatchers.length - 1; i >= 0; i--) {
            var mi = allMatchers[i];
            var expr = mi[0];
            var decl = {};
            var exprBits;
            var blockExprBits;
            var jsCond = '';
            if (expr) {
                if (~expr.indexOf('__')) {
                    exprBits = expr.split('__');
                    blockExprBits = exprBits[0].split('_');
                    decl.block = blockExprBits[0];
                    if (blockExprBits.length > 1) {
                        decl.blockMod = blockExprBits[1];
                        decl.blockModVal = blockExprBits[2];
                    }
                    exprBits = exprBits[1].split('_');
                    decl.elem = exprBits[0];
                    if (exprBits.length > 1) {
                        decl.mod = exprBits[1];
                        decl.modVal = exprBits[2];
                    }
                } else {
                    exprBits = expr.split('_');
                    decl.block = exprBits[0];
                    if (exprBits.length > 1) {
                        decl.mod = exprBits[1];
                        decl.modVal = exprBits[2];
                    }
                }
            }
            if (currentBlock !== decl.block) {
                if (currentBlock) {
                    res.push('}');
                }
                currentBlock = decl.block;
                if (currentBlock) {
                    res.push('if (ctx.block === "' + currentBlock + '") {');
                }
            }
            var conds = [];
            decl.elem && conds.push('ctx.elem === "' + decl.elem + '"');
            decl.block && !decl.elem && conds.push('!ctx.elem');
            decl.mod && conds.push('ctx.mods && ctx.mods.' + decl.mod + ' === "' + decl.modVal + '"');
            if (decl.block && decl.blockMod) {
                conds.push('ctx.blockMods.' + decl.blockMod + ' === "' + decl.blockModVal + '"');
            }
            jsCond && conds.push(jsCond);
            conds.push('!ctx.' + mi[1].__id);
            res.push('if (' + conds.join(' && ') + ') {');
            res.push('ctx.' + mi[1].__id + ' = true;');
            var strFn = mi[1].toString();
            if (~strFn.indexOf('attrs')) {
                res.push('ctx.attrs = ctx.attrs || {};');
            }
            if (~strFn.indexOf('mods')) {
                res.push('ctx.mods = ctx.mods || {};');
            }
            if (~strFn.indexOf('mix')) {
                res.push('ctx.mix = ctx.mix || [];');
{'fraction_non_alphanumeric': 0.15360145421495114, 'fraction_numerical': 0.006816632583503749, 'mean_word_length': 1.1922629918645193, 'pattern_counts': {'":': 0, '<': 6, '<?xml version=': 0, '>': 14, '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': '5024485', 'n_tokens_mistral': 4013, 'n_tokens_neox': 3848, 'n_words': 743}