<commit_before>const Gep = require('gep')

module.exports = hsParse

const gep = new Gep({
  scopes: {
    '_': ['$index', '$event'],
  },
})
const boundMap = {
  'class': ' ',
  'style': ';',
}
const childMap = {
  'text': true,
}

let toRuntime

function hsParse (ejml, debug) {
  toRuntime = !debug
  return translate(ejml)
}

function translate (ejml) {
  if (Array.isArray(ejml)) {
    let childs
    let attrs = parseAttributes(ejml[1], text => {
      childs = text
    })
    if (childs) {
      childs = '[' + childs + ']'
    } else {
      childs = walk(ejml[2])
    }
    return `h('${ejml[0]}',${attrs},${childs})`
  } else {
    return `'${ejml.trim()}'`
  }
}

function walk (childs) {
  return `[${childs
    .map(child => translate(child))
    .filter(child => child && child !== '\'\'')
    .join(',')}]`
}

function parseAttributes (attributes, cb) {
  let keys = Object.keys(attributes)
  if (!keys.length) {
    return '{}'
  }
  let attrs = {}
  let bindAttrs = {}
  let attr, child, slicedKey
  keys.forEach(key => {
    switch (key[0]) {
      case ':':
        slicedKey = key.slice(1)
        attr = getTrimmedAttribute(attributes, slicedKey)
        if (attr) {
          attr = `'${attr}'+(${attributes[key]})`
        } else {
          attr = attributes[key]
        }
        attr = gep.make(gep.parse(attr), toRuntime)
        if (childMap[slicedKey]) {
          child = attr
        } else {
          bindAttrs[slicedKey] = slicedKey + ':' + attr
        }
        break<commit_msg>Use null instead of empty object and empty array<commit_after>const Gep = require('gep')

module.exports = hsParse

const gep = new Gep({
  scopes: {
    '_': ['$index', '$event'],
  },
})
const boundMap = {
  'class': ' ',
  'style': ';',
}
const childMap = {
  'text': true,
}

let toRuntime

function hsParse (ejml, debug) {
  toRuntime = !debug
  return translate(ejml)
}

function translate (ejml) {
  if (Array.isArray(ejml)) {
    let childs
    let attrs = parseAttributes(ejml[1], text => {
      childs = text
    })
    if (childs) {
      childs = '[' + childs + ']'
    } else {
      childs = walk(ejml[2])
    }
    return `h('${ejml[0]}',${attrs},${childs})`
  } else {
    return `'${ejml.trim()}'`
  }
}

function walk (childs) {
  if (!childs.length) {
    return 'null'
  }
  return `[${childs
    .map(child => translate(child))
    .filter(child => child && child !== '\'\'')
    .join(',')}]`
}

function parseAttributes (attributes, cb) {
  let keys = Object.keys(attributes)
  if (!keys.length) {
    return 'null'
  }
  let attrs = {}
  let bindAttrs = {}
  let attr, child, slicedKey
  keys.forEach(key => {
    switch (key[0]) {
      case ':':
        slicedKey = key.slice(1)
        attr = getTrimmedAttribute(attributes, slicedKey)
        if (attr) {
          attr = `'${attr}'+(${attributes[key]})`
        } else {
          attr = attributes[key]
        }
        attr = gep.make(gep.parse(attr), toRuntime)
        if (childMap[slicedKey]) {
          child = attr
        } else {
          bindAttrs[slicedKey] = slicedKey + ':' + attr
        }
        break
{'fraction_non_alphanumeric': 0.17837664420917548, 'fraction_numerical': 0.003208213025344883, 'mean_word_length': 2.403930131004367, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 11, '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': '1955562', 'n_tokens_mistral': 1118, 'n_tokens_neox': 1113, 'n_words': 236}