core/refactor/array.js
function removeFromArray(ast, varName, identifierName) {
  let changes = [];
  traverse(ast, {
    VariableDeclarator(path) {
      const node = path.node;
      if (_.get(node, 'id.name') !== varName || _.get(node, 'init.type') !== 'ArrayExpression')
        return;
      node.init._filePath = ast._filePath;
      const toRemove = _.find(node.init.elements, ele => ele.name === identifierName);
      changes = removeFromArrayByNode(node.init, toRemove);
      path.stop();
    },
  });
  return changes;
}
function removeFromArray(ast, varName, identifierName) {
  let changes = [];
  traverse(ast, {
    VariableDeclarator(path) {
      const node = path.node;
      if (_.get(node, 'id.name') !== varName || _.get(node, 'init.type') !== 'ArrayExpression')
        return;
      node.init._filePath = ast._filePath;
      const toRemove = _.find(node.init.elements, ele => ele.name === identifierName);
      changes = removeFromArrayByNode(node.init, toRemove);
      path.stop();
    },
  });
  return changes;
}
function removeFromArray ( ast , varName , identifierName ) { let changes = [ ] ; traverse ( ast , { VariableDeclarator ( path ) { const node = path . node ; if ( _ . get ( node , 'id.name' ) !== varName || _ . get ( node , 'init.type' ) !== 'ArrayExpression' ) return ; node . init . _filePath = ast . _filePath ; const toRemove = _ . find ( node . init . elements , ele => ele . name === identifierName ) ; changes = removeFromArrayByNode ( node . init , toRemove ) ; path . stop ( ) ; } , } ) ; return changes ; }
Remove an identifier from the array of the name 'varName'.
It only finds the first matched array in the global scope of ast.

@param {object|string} ast - The ast tree or the js file path to find the array.
@param {string} varName - The variable name of the array definition.
@param {string} identifierName - The identifier to append to array.
@alias module:refactor.removeFromArray

@example
const refactor = require('rekit-core').refactor;
// code in ast: const arr = [a, b, c];
refactor.removeFromArray(file, 'arr', 'a');
// code changes to: const arr = [b, c];
Remove an identifier from the array of the name varName . It only finds the first matched array in the global scope of ast .