<commit_before>import {find, transform} from 'lodash';
import recast from 'recast';
import path from 'path';
import fs from 'fs';

import Error from './Error';

const builders = recast.types.builders;

function replaceRequire(node, output) {
  return builders.callExpression(node.callee, [builders.literal(output)]);
}

export const updaters = {
  ImportDeclaration(path, node, output) {
    let source = builders.moduleSpecifier(output);
    let r = builders.importDeclaration(node.specifiers, source);
    path.replace(r);
  },

  AMDImport(path, node, output) {
    path.replace(builders.literal(output));
  },

  CJSImport(path, node, output) {
    switch (node.type) {
      case 'VariableDeclaration': {
        let {id, init} = node.declarations[0];

        path.replace(builders.variableDeclaration(node.kind, [
          builders.variableDeclarator(id, replaceRequire(init, output))
        ]));
        break;
      }
      case 'AssignmentExpression': {<commit_msg>Support updating var declerators<commit_after>import {find, transform} from 'lodash';
import recast from 'recast';
import path from 'path';
import fs from 'fs';

import Error from './Error';

const builders = recast.types.builders;

function replaceRequire(node, output) {
  return builders.callExpression(node.callee, [builders.literal(output)]);
}

export const updaters = {
  ImportDeclaration(path, node, output) {
    let source = builders.moduleSpecifier(output);
    let r = builders.importDeclaration(node.specifiers, source);
    path.replace(r);
  },

  AMDImport(path, node, output) {
    path.replace(builders.literal(output));
  },

  CJSImport(path, node, output) {
    switch (node.type) {
      case 'VariableDeclarator': {
        let {id, init} = node;
        path.replace(builders.variableDeclarator(id,
                        replaceRequire(init, output)));
        break;
      }
      // Annoyingly redundant
      case 'VariableDeclaration': {
        let {id, init} = node.declarations[0];

        path.replace(builders.variableDeclaration(node.kind, [
          builders.variableDeclarator(id, replaceRequire(init, output))
        ]));
        break;
      }
      case 'AssignmentExpression': {
{'fraction_non_alphanumeric': 0.1263062244434348, 'fraction_numerical': 0.0009086778736937755, 'mean_word_length': 3.45748987854251, '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': '4788518', 'n_tokens_mistral': 661, 'n_tokens_neox': 643, 'n_words': 147}