<commit_before>'use strict';

var extend = require('extend-object');
var loaderUtils = require('loader-utils');
var SourceNode = require("source-map").SourceNode;
var SourceMapConsumer = require("source-map").SourceMapConsumer;
var os = require('os');
var traceur = require('traceur');

var defaults = {
  modules: 'commonjs',
  runtime: false,
  sourceMaps: true
};

module.exports = function(source, originalSourceMap) {
  var filename = loaderUtils.getRemainingRequest(this);
  var content = source;
  var map;
  var options = {};
  var result;
  var runtime;
  var imports;

  if (this.cacheable) {
    this.cacheable();
  }

  // Process query and setup options/defaults/forced for Traceur
  extend(options, defaults, loaderUtils.parseQuery(this.query));

  Object.keys(options).forEach(function(key) {
    switch(options[key]) {
      case 'true':
        options[key] = true;
        break;
      case 'false':
        options[key] = false;
        break;
      case 'undefined':
        options[key] = undefined;
        break;
      case 'null':
        options[key] = null;
        break;
    }
  });

  // Move runtime option from options to variable
  runtime = options.runtime;
  delete options.runtime;

  // Include imports
  imports = options.imports === false ? '' : 'imports?global=>window!';
  delete options.imports;

  // Handle Traceur runtime
  if (filename === traceur.RUNTIME_PATH) {
    return content;
  }



  // Parse code through Traceur
  try {
    delete options.runtime;
    var compiler = new traceur.NodeCompiler(options);
    result = compiler.compile(content, filename);

    // Include runtime after compilation due to generators hoisting the
    // runtime usage to the very top
    if (runtime) {
      result = 'require("' + imports + '' + traceur.RUNTIME_PATH + '");' + result;
    }

    // Process source map (if available) and return result
    if (options.sourceMaps) {
      map = JSON.parse(compiler.getSourceMap());
      map.sourcesContent = [source];
      this.callback(null, result, map);
    }
    else {
      return result;
    }
  }
  catch(errors) {
    throw new Error(errors.join(os.EOL));<commit_msg>refactor: recompile souceMaps<commit_after>'use strict';

var extend = require('extend-object');
var loaderUtils = require('loader-utils');
var SourceNode = require("source-map").SourceNode;
var SourceMapConsumer = require("source-map").SourceMapConsumer;
var os = require('os');
var traceur = require('traceur');

var defaults = {
  modules: 'commonjs',
  runtime: false,
  sourceMaps: true
};

module.exports = function(source, originalSourceMap) {
  if (this.cacheable) this.cacheable();
  var filename = loaderUtils.getRemainingRequest(this);
  var content = source;
  var map;
  var options = {};
  var result;
  var runtime;
  var imports;


  // Process query and setup options/defaults/forced for Traceur
  extend(options, defaults, loaderUtils.parseQuery(this.query));

  Object.keys(options).forEach(function(key) {
    switch(options[key]) {
      case 'true':
        options[key] = true;
        break;
      case 'false':
        options[key] = false;
        break;
      case 'undefined':
        options[key] = undefined;
        break;
      case 'null':
        options[key] = null;
        break;
    }
  });

  // Move runtime option from options to variable
  runtime = options.runtime;
  delete options.runtime;

  // Include imports
  imports = options.imports === false ? '' : 'imports?global=>window!';
  delete options.imports;

  // Handle Traceur runtime
  if (filename === traceur.RUNTIME_PATH) {
    return content;
  }



  // Parse code through Traceur
  try {
    delete options.runtime;
    var compiler = new traceur.NodeCompiler(options);
    result = compiler.compile(content, filename);

    // Include runtime after compilation due to generators hoisting the
    // runtime usage to the very top

    // Process source map (if available) and return result
    if (options.sourceMaps && originalSourceMap) {
      var node = SourceNode.fromStringWithSourceMap(result, new SourceMapConsumer(originalSourceMap));
      if (runtime) {
        node.prepend('require("' + imports + '' + traceur.RUNTIME_PATH + '");');
      }
      // node.add(postfix);
      var newSource = node.toStringWithSourceMap({
        file: filename
      });
      this.callback(null, newSource.code, newSource.map.toJSON());
    }
    else if (options.sourceMaps) {
      if (runtime) {
        result = 'require("' + imports + '' + traceur.RUNTIME_PATH + '");' + result;
      }
      map = JSON.parse(compiler.getSourceMap());
      map.sourcesContent = [source];
      this.callback(null, result, map);
    }
    else {
      return result;
    }
  }
  catch(errors) {
    throw new Error(errors.join(os.EOL));
{'fraction_non_alphanumeric': 0.1276106934001671, 'fraction_numerical': 0.0, 'mean_word_length': 3.020990764063812, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, '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': '2024806', 'n_tokens_mistral': 1415, 'n_tokens_neox': 1388, 'n_words': 362}