<commit_before>import { L10nError } from '../../../errors';

export default {
  serialize: function({body, comment}) {
    let string = '';
    if (comment !== null) {
      string += this.dumpComment(comment) + '\n\n';
    }
    for (const entry of body) {
      string += this.dumpEntry(entry);
    }
    return string;
  },

  dumpEntry: function(entry) {
    switch (entry.type) {
      case 'Entity':
        return this.dumpEntity(entry) + '\n';
      case 'Comment':
        return this.dumpComment(entry) + '\n\n';
      case 'Section':
        return this.dumpSection(entry) + '\n';
      case 'JunkEntry':
        return '';
      default:
        throw new L10nError('Unknown entry type.');
    }
  },

  dumpEntity: function(entity) {
    let str = '';

    if (entity.comment) {
      str += this.dumpComment(entity.comment) + '\n';
    }
    const id = this.dumpIdentifier(entity.id);
    const value = this.dumpPattern(entity.value);

    if (entity.traits.length) {
      const traits = this.dumpMembers(entity.traits, 2);
      str += `${id} = ${value}\n${traits}`;
    } else {
      str += `${id} = ${value}`;
    }
    return str;
  },

  dumpComment: function(comment) {
    return '# ' + comment.content.replace(/\n/g, '\n# ');
  },

  dumpSection: function(section) {
    let str = '';
    if (section.comment) {
      str += this.dumpComment(section.comment) + '\n';
    }
    str += `[[ ${this.dumpKeyword(section.key)} ]]\n\n`;<commit_msg>Add empty lines above each section and comment<commit_after>import { L10nError } from '../../../errors';

export default {
  serialize: function({body, comment}) {
    let string = '';
    if (comment !== null) {
      string += this.dumpComment(comment) + '\n\n';
    }
    for (const entry of body) {
      string += this.dumpEntry(entry);
    }
    return string;
  },

  dumpEntry: function(entry) {
    switch (entry.type) {
      case 'Entity':
        return this.dumpEntity(entry) + '\n';
      case 'Comment':
        return this.dumpComment(entry) + '\n\n';
      case 'Section':
        return this.dumpSection(entry) + '\n';
      case 'JunkEntry':
        return '';
      default:
        throw new L10nError('Unknown entry type.');
    }
  },

  dumpEntity: function(entity) {
    let str = '';

    if (entity.comment) {
      str += '\n' + this.dumpComment(entity.comment) + '\n';
    }
    const id = this.dumpIdentifier(entity.id);
    const value = this.dumpPattern(entity.value);

    if (entity.traits.length) {
      const traits = this.dumpMembers(entity.traits, 2);
      str += `${id} = ${value}\n${traits}`;
    } else {
      str += `${id} = ${value}`;
    }
    return str;
  },

  dumpComment: function(comment) {
    return '# ' + comment.content.replace(/\n/g, '\n# ');
  },

  dumpSection: function(section) {
    let str = '\n\n';
    if (section.comment) {
      str += this.dumpComment(section.comment) + '\n';
    }
    str += `[[ ${this.dumpKeyword(section.key)} ]]\n\n`;
{'fraction_non_alphanumeric': 0.18022864828513785, 'fraction_numerical': 0.0033624747814391394, 'mean_word_length': 2.4, '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': '5378899', 'n_tokens_mistral': 974, 'n_tokens_neox': 960, 'n_words': 210}