title: programatically add a function to a javascript file from another javascript
body: <p>I want to add some function/code to java script file from another script. I have the below code in A.js</p>
  
  <pre><code>/*some comments.. about 4-5 lines*/
  module.exports = {
      aaa: aaa,
      add: add
  };
  
  var asd = 'test';
  
  function aaa() {
   console.log('ddddd --- ' + asd);
  }
  
  function add(a, b) {
   var sum = a + b;
   console.log(sum);
  }
  </code></pre>
  
  <p>From another js file i need to add the below function to A.js and update the module.exports list</p>
  
  <pre><code>function diff(c, d) {
     ///some code
  }
  </code></pre>
  
  <p>I parsed the contents of A.js and the new function with esprima parser
  and then with splice function added the code.
  I converted the AST to code with recast and wrote it back to the file But the comments are gone. </p>
  
  <p>How to just insert the code without affecting any other content of the original file?</p>