<commit_before>/**
 * @file 生成元素标签起始的html
 * @author errorrik(<EMAIL>)
 */

var evalExpr = require('../runtime/eval-expr');
var htmlBufferPush = require('../runtime/html-buffer-push');
var htmlBufferTagStart = require('../runtime/html-buffer-tag-start');
var escapeHTML = require('../runtime/escape-html');
var autoCloseTags = require('../browser/auto-close-tags');
var each = require('../util/each');
var getPropAndIndex = require('../util/get-prop-and-index');
var isComponent = require('./is-component');
var handleProp = require('./handle-prop');
var nodeEvalExpr = require('./node-eval-expr');

var BOOL_ATTRIBUTES = {};
each(
    'checked,readonly,selected,multiple,disabled'.split(','),
    function (key) {
        BOOL_ATTRIBUTES[key] = 1;
    }
);

/**
 * 生成元素标签起始的html
 *
 * @param {Element} element 元素
 * @param {Object} buf html串存储对象
 */
function genElementStartHTML(element, buf) {
    var tagName = element.tagName;
    if (!tagName) {
        return;
    }

    htmlBufferPush(buf, '<' + tagName);

    each(element.props, function (prop) {
        var attr = prop.attr;
        var value;

        if (!attr) {
            value = isComponent(element)
                ? evalExpr(prop.expr, element.data, element)
                : nodeEvalExpr(element, prop.expr, 1);

            if (!BOOL_ATTRIBUTES[prop.name] && prop.x) {
                value = escapeHTML(value);
            }

            attr = handleProp.attr(element, prop.name, value);
        }

        htmlBufferPush(buf, attr || '');
    });

    var idProp = getPropAndIndex(element, 'id');
    if (idProp) {
        element._elId = isComponent(element)
            ? evalExpr(idProp.expr, element.data, element)
            : nodeEvalExpr(element, idProp.expr, 1);
    }

    var id = element._elId || element.id;
    htmlBufferPush(buf, ' id="' + id + '"' + '>');
    if (!autoCloseTags[tagName]) {
        htmlBufferTagStart(buf, id);<commit_msg>little opti<commit_after>/**
 * @file 生成元素标签起始的html
 * @author errorrik(<EMAIL>)
 */

var evalExpr = require('../runtime/eval-expr');
var htmlBufferPush = require('../runtime/html-buffer-push');
var htmlBufferTagStart = require('../runtime/html-buffer-tag-start');
var escapeHTML = require('../runtime/escape-html');
var autoCloseTags = require('../browser/auto-close-tags');
var each = require('../util/each');
var getPropAndIndex = require('../util/get-prop-and-index');
var isComponent = require('./is-component');
var handleProp = require('./handle-prop');
var nodeEvalExpr = require('./node-eval-expr');

var BOOL_ATTRIBUTES = {};
each(
    'checked,readonly,selected,multiple,disabled'.split(','),
    function (key) {
        BOOL_ATTRIBUTES[key] = 1;
    }
);

/**
 * 生成元素标签起始的html
 *
 * @param {Element} element 元素
 * @param {Object} buf html串存储对象
 */
function genElementStartHTML(element, buf) {
    var tagName = element.tagName;
    if (!tagName) {
        return;
    }

    var elementIsComponent = isComponent(element);
    htmlBufferPush(buf, '<' + tagName);

    each(element.props, function (prop) {
        var attr = prop.attr;
        var value;

        if (!attr) {
            value = elementIsComponent
                ? evalExpr(prop.expr, element.data, element)
                : nodeEvalExpr(element, prop.expr, 1);

            if (!BOOL_ATTRIBUTES[prop.name] && prop.x) {
                value = escapeHTML(value);
            }

            attr = handleProp.attr(element, prop.name, value);
        }

        htmlBufferPush(buf, attr || '');
    });

    var idProp = getPropAndIndex(element, 'id');
    if (idProp) {
        element._elId = isComponent(element)
            ? evalExpr(idProp.expr, element.data, element)
            : nodeEvalExpr(element, idProp.expr, 1);
    }

    var id = element._elId || element.id;
    htmlBufferPush(buf, ' id="' + id + '"' + '>');
    if (!autoCloseTags[tagName]) {
        htmlBufferTagStart(buf, id);
{'fraction_non_alphanumeric': 0.16312963436461264, 'fraction_numerical': 0.001534134492457172, 'mean_word_length': 2.732824427480916, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, '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': '7039721', 'n_tokens_mistral': 1268, 'n_tokens_neox': 1236, 'n_words': 237}