visitors.js
function renderDesructuration(pattern, expr, traverse, path, state) {
  utils.catchupNewlines(pattern.range[1], state);

  var id;

  if (pattern.type === Syntax.ObjectPattern && pattern.properties.length === 1) {
    id = expr;
  } else if (pattern.type === Syntax.ArrayPattern && pattern.elements.length === 1) {
    id = expr;
  } else {
    id = renderExpressionMemoized(expr, traverse, path, state);
  }

  if (pattern.type === Syntax.ObjectPattern) {

    pattern.properties.forEach(function(prop, idx) {
      var comma = (idx !== pattern.properties.length - 1) ? ', ' : '';

      if (isPattern(prop.value)) {
        renderDesructuration(prop.value, [id, '.', prop.key.name], traverse, path, state);
      } else {
        utils.append(prop.value.name + ' = ', state);
        render([id, '.' + prop.key.name], traverse, path, state);
        utils.append(comma, state);
      }
    });

  } else {

    pattern.elements.forEach(function(elem, idx) {
      // null means skip
      if (elem === null) {
        return;
      }

      var comma = (idx !== pattern.elements.length - 1) ? ', ' : '';

      if (isPattern(elem)) {
        renderDesructuration(elem, [id, '[' + idx + ']'], traverse, path, state);
      } else if (elem.type === Syntax.SpreadElement) {
        utils.append(elem.argument.name + ' = ', state);
        render([id, '.slice(' + idx + ')'], traverse, path, state);
        utils.append(comma, state);
      } else {
        utils.append(elem.name + ' = ', state);
        render([id, '[' + idx + ']'], traverse, path, state);
        utils.append(comma, state);
      }
    });
  }
}
function renderDesructuration(pattern, expr, traverse, path, state) {
  utils.catchupNewlines(pattern.range[1], state);

  var id;

  if (pattern.type === Syntax.ObjectPattern && pattern.properties.length === 1) {
    id = expr;
  } else if (pattern.type === Syntax.ArrayPattern && pattern.elements.length === 1) {
    id = expr;
  } else {
    id = renderExpressionMemoized(expr, traverse, path, state);
  }

  if (pattern.type === Syntax.ObjectPattern) {

    pattern.properties.forEach(function(prop, idx) {
      var comma = (idx !== pattern.properties.length - 1) ? ', ' : '';

      if (isPattern(prop.value)) {
        renderDesructuration(prop.value, [id, '.', prop.key.name], traverse, path, state);
      } else {
        utils.append(prop.value.name + ' = ', state);
        render([id, '.' + prop.key.name], traverse, path, state);
        utils.append(comma, state);
      }
    });

  } else {

    pattern.elements.forEach(function(elem, idx) {
      // null means skip
      if (elem === null) {
        return;
      }

      var comma = (idx !== pattern.elements.length - 1) ? ', ' : '';

      if (isPattern(elem)) {
        renderDesructuration(elem, [id, '[' + idx + ']'], traverse, path, state);
      } else if (elem.type === Syntax.SpreadElement) {
        utils.append(elem.argument.name + ' = ', state);
        render([id, '.slice(' + idx + ')'], traverse, path, state);
        utils.append(comma, state);
      } else {
        utils.append(elem.name + ' = ', state);
        render([id, '[' + idx + ']'], traverse, path, state);
        utils.append(comma, state);
      }
    });
  }
}
function renderDesructuration ( pattern , expr , traverse , path , state ) { utils . catchupNewlines ( pattern . range [ 1 ] , state ) ; var id ; if ( pattern . type === Syntax . ObjectPattern && pattern . properties . length === 1 ) { id = expr ; } else if ( pattern . type === Syntax . ArrayPattern && pattern . elements . length === 1 ) { id = expr ; } else { id = renderExpressionMemoized ( expr , traverse , path , state ) ; } if ( pattern . type === Syntax . ObjectPattern ) { pattern . properties . forEach ( function ( prop , idx ) { var comma = ( idx !== pattern . properties . length - 1 ) ? ', ' : '' ; if ( isPattern ( prop . value ) ) { renderDesructuration ( prop . value , [ id , '.' , prop . key . name ] , traverse , path , state ) ; } else { utils . append ( prop . value . name + ' = ' , state ) ; render ( [ id , '.' + prop . key . name ] , traverse , path , state ) ; utils . append ( comma , state ) ; } } ) ; } else { pattern . elements . forEach ( function ( elem , idx ) { // null means skip if ( elem === null ) { return ; } var comma = ( idx !== pattern . elements . length - 1 ) ? ', ' : '' ; if ( isPattern ( elem ) ) { renderDesructuration ( elem , [ id , '[' + idx + ']' ] , traverse , path , state ) ; } else if ( elem . type === Syntax . SpreadElement ) { utils . append ( elem . argument . name + ' = ' , state ) ; render ( [ id , '.slice(' + idx + ')' ] , traverse , path , state ) ; utils . append ( comma , state ) ; } else { utils . append ( elem . name + ' = ' , state ) ; render ( [ id , '[' + idx + ']' ] , traverse , path , state ) ; utils . append ( comma , state ) ; } } ) ; } }
Render destructuration of the `expr` using provided `pattern`.

@param {Node} pattern Pattern to use for destructuration
@param {Node|String|Array} expr Expression to destructure
@param {Function} traverse
@param {Object} path
@param {Object} state
Render destructuration of the expr using provided pattern .