matches.js
function compileRest (argName, node) {
    var source = [];
    var retInit = [];
    
    // Count the number of identifiers we will need to stash.
    var i = 0, len = countIdentifiers(node);
    for (; i < len; i++) retInit.push('[]');
  
    var retName     = argName + '_ret';
    var loopName    = argName + '_loop';
    var iName       = argName + '_i';
    var lenName     = argName + '_len';
    var retArgsName = argName + '_retargs';
  
    source.push(
      'var ' + retName + ' = [' + retInit.join(',') + '];',
      'var ' + loopName + ' = function (val) {',
      '  var ret = [];',

      indent(2, compilePattern('val', node.children[0])),

      '  return ret;',
      '};',
      'var ' + iName + ' = 0, ' + lenName + ' = ' + argName + '.length, ' + retArgsName + ';',
      'for (; ' + iName + ' < ' + lenName + '; ' + iName + '++) {',
      '  ' + retArgsName + ' = ' + loopName + '(' + argName + '[' + iName + ']);',
      '  if (!' + retArgsName + ') return false;',

      (function () {
        var src = [];
        for (i = 0; i < len; i++) {
          src.push('  ' + retName + '[' + i + '].push(' + retArgsName + '[' + i + ']);');
        }
        return src.join('\n');
      })(),

      '}',
      'ret = Array.prototype.concat.call(ret, ' + retName + ');'
    );
  
    return source.join('\n');
  }
function compileRest (argName, node) {
    var source = [];
    var retInit = [];
    
    // Count the number of identifiers we will need to stash.
    var i = 0, len = countIdentifiers(node);
    for (; i < len; i++) retInit.push('[]');
  
    var retName     = argName + '_ret';
    var loopName    = argName + '_loop';
    var iName       = argName + '_i';
    var lenName     = argName + '_len';
    var retArgsName = argName + '_retargs';
  
    source.push(
      'var ' + retName + ' = [' + retInit.join(',') + '];',
      'var ' + loopName + ' = function (val) {',
      '  var ret = [];',

      indent(2, compilePattern('val', node.children[0])),

      '  return ret;',
      '};',
      'var ' + iName + ' = 0, ' + lenName + ' = ' + argName + '.length, ' + retArgsName + ';',
      'for (; ' + iName + ' < ' + lenName + '; ' + iName + '++) {',
      '  ' + retArgsName + ' = ' + loopName + '(' + argName + '[' + iName + ']);',
      '  if (!' + retArgsName + ') return false;',

      (function () {
        var src = [];
        for (i = 0; i < len; i++) {
          src.push('  ' + retName + '[' + i + '].push(' + retArgsName + '[' + i + ']);');
        }
        return src.join('\n');
      })(),

      '}',
      'ret = Array.prototype.concat.call(ret, ' + retName + ');'
    );
  
    return source.join('\n');
  }
function compileRest ( argName , node ) { var source = [ ] ; var retInit = [ ] ; // Count the number of identifiers we will need to stash. var i = 0 , len = countIdentifiers ( node ) ; for ( ; i < len ; i ++ ) retInit . push ( '[]' ) ; var retName = argName + '_ret' ; var loopName = argName + '_loop' ; var iName = argName + '_i' ; var lenName = argName + '_len' ; var retArgsName = argName + '_retargs' ; source . push ( 'var ' + retName + ' = [' + retInit . join ( ',' ) + '];' , 'var ' + loopName + ' = function (val) {' , '  var ret = [];' , indent ( 2 , compilePattern ( 'val' , node . children [ 0 ] ) ) , '  return ret;' , '};' , 'var ' + iName + ' = 0, ' + lenName + ' = ' + argName + '.length, ' + retArgsName + ';' , 'for (; ' + iName + ' < ' + lenName + '; ' + iName + '++) {' , '  ' + retArgsName + ' = ' + loopName + '(' + argName + '[' + iName + ']);' , '  if (!' + retArgsName + ') return false;' , ( function ( ) { var src = [ ] ; for ( i = 0 ; i < len ; i ++ ) { src . push ( '  ' + retName + '[' + i + '].push(' + retArgsName + '[' + i + ']);' ) ; } return src . join ( '\n' ) ; } ) ( ) , '}' , 'ret = Array.prototype.concat.call(ret, ' + retName + ');' ) ; return source . join ( '\n' ) ; }
The basic idea of rest expressions is that we create another matching function and call that function on all items in the array. We then aggregate all the stashed values and concat them with the `ret` array. We need to know ahead of time how many values are going to be stashed, so we call `countIdentifiers` to traverse the children, returning the number of nodes that can cause a value to be stashed.
The basic idea of rest expressions is that we create another matching function and call that function on all items in the array . We then aggregate all the stashed values and concat them with the ret array . We need to know ahead of time how many values are going to be stashed so we call countIdentifiers to traverse the children returning the number of nodes that can cause a value to be stashed .