<commit_before>#!/usr/bin/env node
Error.stackTraceLimit = Infinity;

const uglify = require('uglify-js');
const Table  = require('cli-table');
const child  = require('child_process');
const bytes  = require('bytes');
const chalk  = require('chalk');
const babel  = require('babel-core');
const zlib   = require('zlib');
const fs     = require('fs');
const path   = require('path');


require('babel-jest/node_modules/babel-core').register();

const filename = process.argv[2];
if (!filename) {
  console.error('Error: No filename specified');
  process.exit(1);
}

const table = new Table({
  head: ['', 'raw', 'raw win', 'gzip', 'gzip win', 'parse time', 'run'],
  chars: {
    top: '',
    'top-mid': '' ,
    'top-left': '' ,
    'top-right': '',
    bottom: '' ,
    'bottom-mid': '' ,
    'bottom-left': '' ,
    'bottom-right': '',
    left: '',
    'left-mid': '',
    mid: '',
    'mid-mid': '',
    right: '' ,
    'right-mid': '',
    middle: ' ',
  },
  style: {
    'padding-left': 0,
    'padding-right': 0,
    head: ['bold'],
  },
});

const results = [];

const code = fs.readFileSync(filename, 'utf8');
const gzippedCode = zlib.gzipSync(code);

function test(name, callback) {
  const start = Date.now();
  const result = callback(code);
  const end = Date.now();
  const run = end - start;

  fs.writeFileSync('.test_gen_' + name + '.js', result);

  const gzipped = zlib.gzipSync(result);

  const parseStart = Date.now();
  // disable for now we have a failing test in dce
  new Function(result);
  const parseEnd = Date.now();
  const parseNow = parseEnd - parseStart;

  results.push({
    name: name,
    raw: result.length,
    gzip: gzipped.length,
    parse: parseNow,
    run: run,
  });
}

test('babel', function (code, callback) {
  return babel.transform(code, {
    sourceType: 'script',
    plugins: [
      [
        require('../src/replace-plugin'),
        {
          replacements: [{
            identifierName: '__DEV__',
            replacement: {
              type: 'booleanLiteral',
              value: true,
            },
          }],
        },
      ],
      require('../src/constant-folding-plugin'),
      require('../src/dce-plugin'),
      require('../src/simplify-plugin'),

      require('../src/mangle-names-plugin'),
    ],
    minified: true,
    comments: false,
  }).code;
});

if (filename.match(/fb\.js/)) {
  test('jsxmin', function (code, callback) {
    return fs.readFileSync(path.join(__dirname, 'fb-jsmin.js'));
  });
}

test('closure', function (code, callback) {
  return child.execSync(<commit_msg>reorder<commit_after>#!/usr/bin/env node
Error.stackTraceLimit = Infinity;

const uglify = require('uglify-js');
const Table  = require('cli-table');
const child  = require('child_process');
const bytes  = require('bytes');
const chalk  = require('chalk');
const babel  = require('babel-core');
const zlib   = require('zlib');
const fs     = require('fs');
const path   = require('path');


require('babel-jest/node_modules/babel-core').register();

const filename = process.argv[2];
if (!filename) {
  console.error('Error: No filename specified');
  process.exit(1);
}

const table = new Table({
  head: ['', 'raw', 'raw win', 'gzip', 'gzip win', 'parse time', 'run'],
  chars: {
    top: '',
    'top-mid': '' ,
    'top-left': '' ,
    'top-right': '',
    bottom: '' ,
    'bottom-mid': '' ,
    'bottom-left': '' ,
    'bottom-right': '',
    left: '',
    'left-mid': '',
    mid: '',
    'mid-mid': '',
    right: '' ,
    'right-mid': '',
    middle: ' ',
  },
  style: {
    'padding-left': 0,
    'padding-right': 0,
    head: ['bold'],
  },
});

const results = [];

const code = fs.readFileSync(filename, 'utf8');
const gzippedCode = zlib.gzipSync(code);

function test(name, callback) {
  const start = Date.now();
  const result = callback(code);
  const end = Date.now();
  const run = end - start;

  fs.writeFileSync('.test_gen_' + name + '.js', result);

  const gzipped = zlib.gzipSync(result);

  const parseStart = Date.now();
  // disable for now we have a failing test in dce
  new Function(result);
  const parseEnd = Date.now();
  const parseNow = parseEnd - parseStart;

  results.push({
    name: name,
    raw: result.length,
    gzip: gzipped.length,
    parse: parseNow,
    run: run,
  });
}

test('babel', function (code, callback) {
  return babel.transform(code, {
    sourceType: 'script',
    plugins: [
      [
        require('../src/replace-plugin'),
        {
          replacements: [{
            identifierName: '__DEV__',
            replacement: {
              type: 'booleanLiteral',
              value: true,
            },
          }],
        },
      ],
      require('../src/constant-folding-plugin'),
      require('../src/mangle-names-plugin'),
      require('../src/dce-plugin'),
      require('../src/simplify-plugin'),
    ],
    minified: true,
    comments: false,
  }).code;
});

if (filename.match(/fb\.js/)) {
  test('jsxmin', function (code, callback) {
    return fs.readFileSync(path.join(__dirname, 'fb-jsmin.js'));
  });
}

test('closure', function (code, callback) {
  return child.execSync(
{'fraction_non_alphanumeric': 0.19021633209900604, 'fraction_numerical': 0.0019489378288832587, 'mean_word_length': 2.740524781341108, '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': '5070287', 'n_tokens_mistral': 1735, 'n_tokens_neox': 1700, 'n_words': 371}