<commit_before>jest.autoMockOff();

const babel = require('babel-core');

function transform(code) {
  return babel.transform(code,  {
    plugins: [require('../index')],
    blacklist: ['strict'],
  }).code;
}

function unpad(str) {
  const lines = str.split('\n');
  const m = lines[1] && lines[1].match(/^\s+/);
  if (!m) {
    return str;
  }
  const spaces = m[0].length;
  return lines.map(
    line => line.slice(spaces)
  ).join('\n').trim();
}

describe('dce-plugin', () => {
  it('should remove bindings with no references', () => {
    const expected = '';
    const source = 'var x = 1;';
    expect(transform(source)).toBe(expected);
  });

  it('should inline binding with one reference', () => {
    const expected = 'console.log(1);';
    const source = unpad(`
      var x = 1;
      console.log(x);
    `);

    expect(transform(source).trim()).toBe(expected);
  });

  it('should remove side effectless statements', () => {
    const expected = unpad(`
      function x() {}
    `);
    const source = unpad(`
      function x() {
        1;
      }
    `);

    expect(transform(source).trim()).toBe(expected);
  });

  it('should work with multiple scopes', () => {
    const expected = unpad(`
      function x() {
        function y() {
          console.log(1);
        }
      }
    `);
    const source = unpad(`
      function x() {
        var i = 1;
        function y() {
          console.log(i);
        }
      }
    `);

    expect(transform(source).trim()).toBe(expected);
  });

  it('should not inline function expressions', () => {
    const expected = unpad(`
      var x = function x() {
        return 1;
      };
      x();
    `);
    const source = unpad(`
      var x = function() {
        return 1;
      };
      x();
    `);

    expect(transform(source).trim()).toBe(expected);
  });
});<commit_msg>Add failing test<commit_after>jest.autoMockOff();

const babel = require('babel-core');

function transform(code) {
  return babel.transform(code,  {
    plugins: [require('../index')],
    blacklist: ['strict'],
  }).code;
}

function unpad(str) {
  const lines = str.split('\n');
  const m = lines[1] && lines[1].match(/^\s+/);
  if (!m) {
    return str;
  }
  const spaces = m[0].length;
  return lines.map(
    line => line.slice(spaces)
  ).join('\n').trim();
}

describe('dce-plugin', () => {
  it('should remove bindings with no references', () => {
    const expected = '';
    const source = 'var x = 1;';
    expect(transform(source)).toBe(expected);
  });

  it('should inline binding with one reference', () => {
    const expected = 'console.log(1);';
    const source = unpad(`
      var x = 1;
      console.log(x);
    `);

    expect(transform(source).trim()).toBe(expected);
  });

  it('should remove side effectless statements', () => {
    const expected = unpad(`
      function x() {}
    `);
    const source = unpad(`
      function x() {
        1;
      }
    `);

    expect(transform(source).trim()).toBe(expected);
  });

  it('should work with multiple scopes', () => {
    const expected = unpad(`
      function x() {
        function y() {
          console.log(1);
        }
      }
    `);
    const source = unpad(`
      function x() {
        var i = 1;
        function y() {
          console.log(i);
        }
      }
    `);

    expect(transform(source).trim()).toBe(expected);
  });

  it('should not inline function expressions', () => {
    const expected = unpad(`
      var x = function x() {
        return 1;
      };
      x();
    `);
    const source = unpad(`
      var x = function() {
        return 1;
      };
      x();
    `);

    expect(transform(source).trim()).toBe(expected);
  });

  // bug in babel https://github.com/babel/babel/issues/2570
  it('should not inline vars with multiple references', () => {
    const expected = unpad(`
      var x = function() {
        if (!y) {
          y = 1;
        }
      };
      x();
      var y = null;
    `);
    const source = unpad(`
      var x = function() {
        if (!y) {
          y = 1;
        }
      };
      x();
      var y = null;
    `);

    expect(transform(source).trim()).toBe(expected);
  });
});
{'fraction_non_alphanumeric': 0.18479560124312694, 'fraction_numerical': 0.006693760459000717, 'mean_word_length': 2.115413253909159, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 18, 'https://': 1, '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': '3303043', 'n_tokens_mistral': 1364, 'n_tokens_neox': 1321, 'n_words': 308}