code: function updateSourceCode(code, changes) {
    // Summary:
    //  This must be called before code is changed some places else rather than ast
  
    changes.sort((c1, c2) => c2.start - c1.start);
    // Remove same or overlapped changes
    const newChanges = _.reduce(
      changes,
      (cleanChanges, curr) => {
        const last = _.last(cleanChanges);
  
        if (!cleanChanges.length || last.start > curr.end) {
          cleanChanges.push(curr);
        } else if (last.start === last.end && last.end === curr.start && curr.start === curr.end) {
          // insert code at the same position, merge them
          last.replacement += curr.replacement;
        }
        return cleanChanges;
      },
      [],
    );
  
    const chars = code.split('');
    newChanges.forEach(c => {
      // Special case: after the change, two empty lines occurs, should delete one line
      if (
        c.replacement === '' &&
        (c.start === 0 || chars[c.start - 1] === '\n') &&
        chars[c.end] === '\n'
      ) {
        c.end += 1;
      }
      chars.splice(c.start, c.end - c.start, c.replacement);
    });
    return chars.join('');
  }
docs: const utils = require('../../common/utils');