text: // Generated by CoffeeScript 1.10.0
  (function() {
    var _, imitate, isConstructor, log, reset, stringifyAnything, warnIfTypeMismatch, wrapIfNeeded, wrapWithConstructor;
  
    _ = {
      capitalize: require('lodash/capitalize')
    };
  
    imitate = require('./imitate');
  
    isConstructor = require('./is-constructor');
  
    wrapWithConstructor = require('./wrap-with-constructor');
  
    log = require('../log');
  
    reset = require('../reset');
  
    stringifyAnything = require('../stringify/anything');
  
    module.exports = function(object, property, manualReplacement) {
      var fakeThing, isManual, realThing, realThingExists;
      isManual = arguments.length > 2;
      realThingExists = object[property] || object.hasOwnProperty(property);
      if (!isManual && !realThingExists) {
        log.error("td.replace", "No \"" + property + "\" property was found.");
      }
      realThing = object[property];
      fakeThing = isManual ? (warnIfTypeMismatch(property, manualReplacement, realThing), manualReplacement) : imitate(realThing, property);
      object[property] = wrapIfNeeded(fakeThing, realThing);
      reset.onNextReset(function() {
        if (realThingExists) {
          return object[property] = realThing;
        } else {
          return delete object[property];
        }
      });
      return fakeThing;
    };
  
    wrapIfNeeded = function(fakeThing, realThing) {
      if (isConstructor(realThing)) {
        return wrapWithConstructor(fakeThing);
      } else {
        return fakeThing;
      }
    };
  
    warnIfTypeMismatch = function(property, fakeThing, realThing) {
      var fakeType, realType;
      if (realThing === void 0) {
        return;
      }
      fakeType = typeof fakeThing;
      realType = typeof realThing;
      if (fakeType !== realType) {
        return log.warn("td.replace", "property \"" + property + "\" " + (stringifyAnything(realThing)) + " (" + (_.capitalize(realType)) + ") was replaced with " + (stringifyAnything(fakeThing)) + ", which has a different type (" + (_.capitalize(fakeType)) + ").");
      }
    };
  
  }).call(this);
  