<commit_before>'use strict';

const babel = require('babel-core');
const babelPresetEnv = require('babel-preset-env');
const CleanCss = require('clean-css');
const strings = require('oc-templates-messages');
const uglifyJs = require('uglify-js');

module.exports = function(fileExtension, fileContent) {
  if (fileExtension === '.js') {
    const presetOptions = {
      targets: {
        browsers: 'ie 8',
        uglify: true
      },
      useBuiltIns: true,
      modules: false
    };

    const babelOptions = { presets: [[babelPresetEnv, presetOptions]] };
    const es5TranspiledContent = babel.transform(fileContent, babelOptions)
      .code;

    return uglifyJs.minify(es5TranspiledContent, { fromString: true }).code;
  } else if (fileExtension === '.css') {
    const result = new CleanCss().minify(fileContent);

    if (result.warnings.length > 0 || result.errors.lenght > 0) {
      throw new Error(strings.errors.cssNotValid());
    }

    return result.styles;
  }
};<commit_msg>fromString is not a valid option anymore and throw<commit_after>'use strict';

const babel = require('babel-core');
const babelPresetEnv = require('babel-preset-env');
const CleanCss = require('clean-css');
const strings = require('oc-templates-messages');
const uglifyJs = require('uglify-js');

module.exports = function(fileExtension, fileContent) {
  if (fileExtension === '.js') {
    const presetOptions = {
      targets: {
        browsers: 'ie 8',
        uglify: true
      },
      useBuiltIns: true,
      modules: false
    };

    const babelOptions = { presets: [[babelPresetEnv, presetOptions]] };
    const es5TranspiledContent = babel.transform(fileContent, babelOptions)
      .code;

    const uglified = uglifyJs.minify(es5TranspiledContent);

    if (uglified.error) {
      throw new Error(uglified.error);
    }
    return uglified.code;
  } else if (fileExtension === '.css') {
    const result = new CleanCss().minify(fileContent);

    if (result.warnings.length > 0 || result.errors.lenght > 0) {
      throw new Error(strings.errors.cssNotValid());
    }

    return result.styles;
  }
};
{'fraction_non_alphanumeric': 0.13657844990548204, 'fraction_numerical': 0.004725897920604915, 'mean_word_length': 3.4568421052631577, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 7, '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': '7127963', 'n_tokens_mistral': 682, 'n_tokens_neox': 662, 'n_words': 149}