function inline_scope_instance (source_scope, instance, computables, input_computables) {
  var target_scope = instance.get_containing_scope();
  var clone_map = {};
  var output_map = {};

  var input_length = input_computables.length;
  var i, j, computable, field_name, target_input;

  // Store instance inputs to replace scope parameter computables
  for (i = 0; i < input_length; ++i) {
    computable = input_computables[i];
    target_input = instance.get_input(i);
    clone_map[computable.get_identity()] = target_input;
  }

  // Clone all non-input computables
  for (i = 0; i < computables.length; i++) {
    computable = computables[i];
    var computable_id = computable.get_identity();

    var input_clones = [];
    var input_count = computable.get_input_count();
    for (j = 0; j < input_count; j++) {
      var input = computable.get_input(j);
      var input_clone = clone_map[input.get_identity()];
      input_clones.push(input_clone);
    }

    var clone = computable.clone(input_clones, target_scope);
    clone_map[computable_id] = clone;

    if (source_scope.is_output(computable)) {
      var output_index = source_scope.get_output_index(computable);
      field_name = source_scope.get_output_field_name(output_index);
      output_map[field_name] = clone;
    }
  }

  // Replace dependees' dependees' inputs with output clone
  var dependee_count = instance.get_dependee_count();
  for (i = 0; i < dependee_count; i++) {
    var dependee = instance.get_dependee(i);
    field_name = dependee.get_field_name();
    var output_computable_clone = output_map[field_name];

    if (!output_computable_clone) {
      throw new Error('Unable to find output computable: ' + field_name);
    }

    if (target_scope.is_output(dependee)) {
      target_scope.replace_output(output_computable_clone, field_name);
    }

    // Dependee array gets spliced, so use while loop
    while (dependee.get_dependee_count()) {
      var second_dependee = dependee.get_dependee(0);
      var input_indices = second_dependee.get_input_indices(dependee);
      for (j = 0; j < input_indices.length; j++) {
        second_dependee.set_input(input_indices[j], output_computable_clone);
      }
    }
  }

  // Destroy the instance and all its direct dependees
  instance.destroy();
}
/**
 * Take a scope instance that can be inlined and clone its computables into
 * the containing scope. Also, do cleanup on the instance and destroy it after
 * it is cloned.
 *
 * @param {Scope} source_scope The scope to inline
 * @param {ScopeInstance} instance The instance of the scope that is being cloned
 * @param {Array} computables Array of computables that are not input computables
 * @param {Array} input_computables
 */
Take a scope instance that can be inlined and clone its computables into
the containing scope. Also, do cleanup on the instance and destroy it after
it is cloned.

@param {Scope} source_scope The scope to inline
@param {ScopeInstance} instance The instance of the scope that is being cloned
@param {Array} computables Array of computables that are not input computables
@param {Array} input_computables
Take a scope instance that can be inlined and clone its computables into the containing scope . Also do cleanup on the instance and destroy it after it is cloned . @param { Scope } source_scope The scope to inline @param { ScopeInstance } instance The instance of the scope that is being cloned @param { Array } computables Array of computables that are not input computables @param { Array } input_computables
function inline_scope_instance (source_scope, instance, computables, input_computables) {
  var target_scope = instance.get_containing_scope();
  var clone_map = {};
  var output_map = {};
  var input_length = input_computables.length;
  var i, j, computable, field_name, target_input;
  for (i = 0; i < input_length; ++i) {
    computable = input_computables[i];
    target_input = instance.get_input(i);
    clone_map[computable.get_identity()] = target_input;
  }
  for (i = 0; i < computables.length; i++) {
    computable = computables[i];
    var computable_id = computable.get_identity();
    var input_clones = [];
    var input_count = computable.get_input_count();
    for (j = 0; j < input_count; j++) {
      var input = computable.get_input(j);
      var input_clone = clone_map[input.get_identity()];
      input_clones.push(input_clone);
    }
    var clone = computable.clone(input_clones, target_scope);
    clone_map[computable_id] = clone;
    if (source_scope.is_output(computable)) {
      var output_index = source_scope.get_output_index(computable);
      field_name = source_scope.get_output_field_name(output_index);
      output_map[field_name] = clone;
    }
  }
  var dependee_count = instance.get_dependee_count();
  for (i = 0; i < dependee_count; i++) {
    var dependee = instance.get_dependee(i);
    field_name = dependee.get_field_name();
    var output_computable_clone = output_map[field_name];
    if (!output_computable_clone) {
      throw new Error('Unable to find output computable: ' + field_name);
    }
    if (target_scope.is_output(dependee)) {
      target_scope.replace_output(output_computable_clone, field_name);
    }
    while (dependee.get_dependee_count()) {
      var second_dependee = dependee.get_dependee(0);
      var input_indices = second_dependee.get_input_indices(dependee);
      for (j = 0; j < input_indices.length; j++) {
        second_dependee.set_input(input_indices[j], output_computable_clone);
      }
    }
  }
  instance.destroy();
}
function inline_scope_instance ( source_scope , instance , computables , input_computables ) { var target_scope = instance . get_containing_scope ( ) ; var clone_map = { } ; var output_map = { } ; var input_length = input_computables . length ; var i , j , computable , field_name , target_input ; for ( i = 0 ; i < input_length ; ++ i ) { computable = input_computables [ i ] ; target_input = instance . get_input ( i ) ; clone_map [ computable . get_identity ( ) ] = target_input ; } for ( i = 0 ; i < computables . length ; i ++ ) { computable = computables [ i ] ; var computable_id = computable . get_identity ( ) ; var input_clones = [ ] ; var input_count = computable . get_input_count ( ) ; for ( j = 0 ; j < input_count ; j ++ ) { var input = computable . get_input ( j ) ; var input_clone = clone_map [ input . get_identity ( ) ] ; input_clones . push ( input_clone ) ; } var clone = computable . clone ( input_clones , target_scope ) ; clone_map [ computable_id ] = clone ; if ( source_scope . is_output ( computable ) ) { var output_index = source_scope . get_output_index ( computable ) ; field_name = source_scope . get_output_field_name ( output_index ) ; output_map [ field_name ] = clone ; } } var dependee_count = instance . get_dependee_count ( ) ; for ( i = 0 ; i < dependee_count ; i ++ ) { var dependee = instance . get_dependee ( i ) ; field_name = dependee . get_field_name ( ) ; var output_computable_clone = output_map [ field_name ] ; if ( ! output_computable_clone ) { throw new Error ( 'Unable to find output computable: ' + field_name ) ; } if ( target_scope . is_output ( dependee ) ) { target_scope . replace_output ( output_computable_clone , field_name ) ; } while ( dependee . get_dependee_count ( ) ) { var second_dependee = dependee . get_dependee ( 0 ) ; var input_indices = second_dependee . get_input_indices ( dependee ) ; for ( j = 0 ; j < input_indices . length ; j ++ ) { second_dependee . set_input ( input_indices [ j ] , output_computable_clone ) ; } } } instance . destroy ( ) ; }
Take a scope instance that can be inlined and clone its computables into
 the containing scope.
Take a scope instance that can be inlined and clone its computables into the containing scope .
// Store instance inputs to replace scope parameter computables // Clone all non-input computables // Replace dependees' dependees' inputs with output clone // Dependee array gets spliced, so use while loop // Destroy the instance and all its direct dependees