<commit_before>const transform = require('gulp-transform-js-ast');
const rename = require('gulp-es6-imports-renamer');
const replace = require('gulp-replace');

const CORE_PACKAGE_NAME = 'angular2-modal';
const CORE_IMPORT_REGEX = /^(.*\.\.?\/components\/angular2-modal)(.*)$/;


function renameFn(originalPath, parentPath, callback) {
  var match = CORE_IMPORT_REGEX.exec(originalPath);
  if ( match !== null) {
    callback(null, originalPath.replace(CORE_IMPORT_REGEX, `${CORE_PACKAGE_NAME}$2`));
  } else {
    callback(null, originalPath);
  }
}

const visitCallExpression = (function() {
  function isRequireMethod (path) {
    var node = path.value;

    return node.type === 'CallExpression' &&
      node.callee &&
      node.callee.type === 'Identifier' &&
      node.callee.name === 'require';
  }

  function isLiteral(path) {
    var args = path.value.arguments;
    return args &&
      args.length === 1 &&
      args[0].type === 'Literal';
  }

  function isCandidate(path) {
    return isRequireMethod(path) && isLiteral(path);
  }

  return function visitCallExpression(path) {
    if (isCandidate(path)) {
      var match,
        arg = path.value.arguments["0"];
      if ((match = CORE_IMPORT_REGEX.exec(arg.value)) !== null) {
        arg.value = arg.value.replace(CORE_IMPORT_REGEX, `${CORE_PACKAGE_NAME}$2`);
      }
    }
    return path.value;
  }
})();


function tsDefinitionImportRename() {
  const CORE_IMPORT_REGEX = /^(import {.+} from ['"])(.*\/components\/angular2-modal)(['"];?)$/m;
  return replace(CORE_IMPORT_REGEX, `$1${CORE_PACKAGE_NAME}$3`);
}

module.exports.tsDefinitionImportRename = tsDefinitionImportRename();
module.exports.es6ImportRename = rename({renameFn: renameFn});
module.exports.es5RequireVisitor = transform( { visitCallExpression: visitCallExpression } );<commit_msg>fix: be greedy when replacing d.ts imports<commit_after>const transform = require('gulp-transform-js-ast');
const rename = require('gulp-es6-imports-renamer');
const replace = require('gulp-replace');

const CORE_PACKAGE_NAME = 'angular2-modal';
const CORE_IMPORT_REGEX = /^(.*\.\.?\/components\/angular2-modal)(.*)$/;


function renameFn(originalPath, parentPath, callback) {
  var match = CORE_IMPORT_REGEX.exec(originalPath);
  if ( match !== null) {
    callback(null, originalPath.replace(CORE_IMPORT_REGEX, `${CORE_PACKAGE_NAME}$2`));
  } else {
    callback(null, originalPath);
  }
}

const visitCallExpression = (function() {
  function isRequireMethod (path) {
    var node = path.value;

    return node.type === 'CallExpression' &&
      node.callee &&
      node.callee.type === 'Identifier' &&
      node.callee.name === 'require';
  }

  function isLiteral(path) {
    var args = path.value.arguments;
    return args &&
      args.length === 1 &&
      args[0].type === 'Literal';
  }

  function isCandidate(path) {
    return isRequireMethod(path) && isLiteral(path);
  }

  return function visitCallExpression(path) {
    if (isCandidate(path)) {
      var match,
        arg = path.value.arguments["0"];
      if ((match = CORE_IMPORT_REGEX.exec(arg.value)) !== null) {
        arg.value = arg.value.replace(CORE_IMPORT_REGEX, `${CORE_PACKAGE_NAME}$2`);
      }
    }
    return path.value;
  }
})();


function tsDefinitionImportRename() {
  const CORE_IMPORT_REGEX = /^(import {.+} from ['"])(.*\/components\/angular2-modal)(['"];?)$/mg;
  return replace(CORE_IMPORT_REGEX, `$1${CORE_PACKAGE_NAME}$3`);
}

module.exports.tsDefinitionImportRename = tsDefinitionImportRename();
module.exports.es6ImportRename = rename({renameFn: renameFn});
module.exports.es5RequireVisitor = transform( { visitCallExpression: visitCallExpression } );
{'fraction_non_alphanumeric': 0.16204458945078848, 'fraction_numerical': 0.0070690592713431215, 'mean_word_length': 4.1097222222222225, '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': '7452857', 'n_tokens_mistral': 1205, 'n_tokens_neox': 1197, 'n_words': 208}