<commit_before>var fs = require('fs');
var babel = require('babel');

function generateSourceMap(map){
  function toBase64(string){
    return new Buffer(string).toString('base64');
  }

  var mapStr = JSON.stringify(map);

  // align `?instr` in filename to fold 4
  mapStr = mapStr.replace(/(,"sources":\[)("[^"]+")/, function(m, prefix, filename){
    while (filename.length % 3 != 1)
      filename = ' ' + filename;
    return prefix + filename;
  });
  
  // return comment for inject to js
  return (
    '\n//# sourceMappingURL=data:application/json;charset=utf-8;base64,' +
    toBase64(mapStr)
  );
}

module.exports = function(options){
  var registratorName = options.registratorName;

  return function instrumentCode(content, filename, cb){
    content = String(content || '');
    filename = filename || 'unknown';

    var instrumentedCode = babel.transform(content, {
      filename: filename,
      sourceMaps: true,
      sourceFileName: filename + '?instr',
      plugins: [
        require('babel-plugin-source-wrapper')({
          registratorName: registratorName
        })
      ],
      whitelist: [],         // prevent use any other transformers
      blacklist: ['strict']  // prevent add "use strict" to sources
    });

    cb(null, instrumentedCode.code +
      generateSourceMap({
        version: instrumentedCode.map.version,
        sections: [{
          offset: { line: 0, column: 0 },
          map: instrumentedCode.map
        }]
      })
    );
  }
};
<commit_msg>report about error if any<commit_after>var fs = require('fs');
var babel = require('babel');

function generateSourceMap(map){
  function toBase64(string){
    return new Buffer(string).toString('base64');
  }

  var mapStr = JSON.stringify(map);

  // align `?instr` in filename to fold 4
  mapStr = mapStr.replace(/(,"sources":\[)("[^"]+")/, function(m, prefix, filename){
    while (filename.length % 3 != 1)
      filename = ' ' + filename;
    return prefix + filename;
  });
  
  // return comment for inject to js
  return (
    '\n//# sourceMappingURL=data:application/json;charset=utf-8;base64,' +
    toBase64(mapStr)
  );
}

module.exports = function(options){
  var registratorName = options.registratorName;

  return function instrumentCode(content, filename, cb){
    content = String(content || '');
    filename = filename || 'unknown';

    try {
      var instrumentedCode = babel.transform(content, {
        filename: filename,
        sourceMaps: true,
        sourceFileName: filename + '?instr',
        plugins: [
          require('babel-plugin-source-wrapper')({
            registratorName: registratorName
          })
        ],
        whitelist: [],         // prevent use any other transformers
        blacklist: ['strict']  // prevent add "use strict" to sources
      });

      cb(null, instrumentedCode.code +
        generateSourceMap({
          version: instrumentedCode.map.version,
          sections: [{
            offset: { line: 0, column: 0 },
            map: instrumentedCode.map
          }]
        })
      );
    } catch(e) {
      cb(e);
    }
  }
};

{'fraction_non_alphanumeric': 0.1404241645244216, 'fraction_numerical': 0.008997429305912597, 'mean_word_length': 2.6113689095127612, 'pattern_counts': {'":': 2, '<': 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': '5644985', 'n_tokens_mistral': 934, 'n_tokens_neox': 901, 'n_words': 213}