core/refactor/array.js
function addToArray(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;
      changes = addToArrayByNode(node.init, identifierName);
      path.stop();
    },
  });
  return changes;
}
function addToArray(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;
      changes = addToArrayByNode(node.init, identifierName);
      path.stop();
    },
  });
  return changes;
}
function addToArray ( 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 ; changes = addToArrayByNode ( node . init , identifierName ) ; path . stop ( ) ; } , } ) ; return changes ; }
Add an identifier to the array of the name 'varName'.
It only finds the first matched array in the top 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.addToArray

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