<commit_before>var fs = require('fs');
var createSourceMapLocatorPreprocessor = function(args, logger, helper) {
  var log = logger.create('preprocessor.sourcemap');

  return function(content, file, done) {
    var mapPath = file.path+".map";
    fs.exists(mapPath, function(exists) {
      if (!exists) {
        done(content);
        return;
      }
      fs.readFile(mapPath, function(err, data) {
        if (err) throw err;
        file.sourceMap = JSON.parse(data);
        done(content);
      });
    });
  };
};<commit_msg>feat: inline source maps<commit_after>var fs = require('fs');

var createSourceMapLocatorPreprocessor = function(args, logger, helper) {
  var log = logger.create('preprocessor.sourcemap');

  return function(content, file, done) {
    var match = content.match(/#\s*sourceMappingURL=(data:application\/json.+)$/m);
    if (match !== null && match.length == 2) {
      // inline source map
      var data;
      var b64Match = match[1].match(/^data:.+\/(.+);base64,(.*)$/);
      if (b64Match !== null && b64Match.length == 3) {
        // base64-encoded JSON string
        log.debug('base64-encoded source map for', file.originalPath);
        var buffer = new Buffer(b64Match[2], 'base64');
        data = buffer.toString();
      } else {
        // straight-up URL-encoded JSON string
        log.debug('raw inline source map for', file.originalPath);
        data = decodeURIComponent(match[1].slice('data:application/json'.length));
      }
      file.sourceMap = JSON.parse(data);
      done(content);
    } else {
      var mapPath = file.path+".map";
      fs.exists(mapPath, function(exists) {
        if (!exists) {
          done(content);
          return;
        }
        fs.readFile(mapPath, function(err, data) {
          if (err) throw err;
          log.debug('external source map exists for', file.originalPath);
          file.sourceMap = JSON.parse(data);
          done(content);
        });
      });
    }
  };
};
{'fraction_non_alphanumeric': 0.1539240506329114, 'fraction_numerical': 0.010632911392405063, 'mean_word_length': 2.5412186379928317, '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': '5943637', 'n_tokens_mistral': 604, 'n_tokens_neox': 590, 'n_words': 130}