Repository: rtfeldman/seamless-immutable
Pull request #47 (2015-06-12 05:27:31)

Issue#45 Potential fix


Patch:
diff --git a/seamless-immutable.development.js b/seamless-immutable.development.js
index b64fa83..815d6ef 100644
--- a/seamless-immutable.development.js
+++ b/seamless-immutable.development.js
@@ -214,7 +214,7 @@
   }
 
   function asDeepMutable(obj) {
-    if( !obj || !obj.hasOwnProperty(immutabilityTag) ) { return obj; }
+    if(obj instanceof Date || !obj || !obj.hasOwnProperty(immutabilityTag) ) { return obj; }
     return obj.asMutable({deep: true});
   }
 
diff --git a/seamless-immutable.production.min.js b/seamless-immutable.production.min.js
index 43dbe78..00b18f7 100644
--- a/seamless-immutable.production.min.js
+++ b/seamless-immutable.production.min.js
@@ -1,1 +1,1 @@
-!function(){"use strict";function a(a,b,c){Object.defineProperty(a,b,{enumerable:!1,configurable:!1,writable:!1,value:c})}function b(b){a(b,s,!0)}function c(a){return"object"==typeof a?null===a||a.hasOwnProperty(s):!0}function d(a){return!(null===a||"object"!=typeof a||a instanceof Array||a instanceof Date)}function e(a){var b=new Error(a);return b.__proto__=e,b}function f(a,c){b(a);return a}function g(b,c){var d=b[c];a(b,c,function(){return r(d.apply(b,arguments))})}function h(b){for(var c in w)if(w.hasOwnProperty(c)){var d=w[c];g(b,d)}a(b,"flatMap",i),a(b,"asObject",l),a(b,"asMutable",k);for(var e=0,h=b.length;h>e;e++)b[e]=r(b[e]);return f(b,v)}function i(a){if(0===arguments.length)return this;var b,c=[],d=this.length;for(b=0;d>b;b++){var e=a(this[b],b,this);e instanceof Array?c.push.apply(c,e):c.push(e)}return h(c)}function j(a){if(0===arguments.length)return this;a instanceof Array||(a=Array.prototype.slice.call(arguments));var b={};for(var c in this)this.hasOwnProperty(c)&&-1===a.indexOf(c)&&(b[c]=this[c]);return q(b)}function k(a){var b,c,d=[];if(a&&a.deep)for(b=0,c=this.length;c>b;b++)d.push(m(this[b]));else for(b=0,c=this.length;c>b;b++)d.push(this[b]);return d}function l(a){"function"!=typeof a&&(a=function(a){return a});var b,c={},d=this.length;for(b=0;d>b;b++){var e=a(this[b],b,this),f=e[0],g=e[1];c[f]=g}return q(c)}function m(a){return a&&a.hasOwnProperty(s)?a.asMutable({deep:!0}):a}function n(a,b){for(var c in a)a.hasOwnProperty(c)&&(b[c]=a[c]);return b}function o(a,b){function c(a,c,e){var h=r(c[e]),k=j&&j(a[e],h,b);j&&k&&k===a[e]||(f=f||void 0!==k||!a.hasOwnProperty(e)||h!==a[e]&&h===h,g[e]=k?k:i&&d(a[e])&&d(h)?a[e].merge(h,b):h)}if(0===arguments.length)return this;if(null===a||"object"!=typeof a)throw new TypeError("Immutable#merge can only be invoked with objects or arrays, not "+JSON.stringify(a));var e,f=!1,g=n(this,{}),h=a instanceof Array,i=b&&b.deep,j=b&&b.merger;if(h)for(var k=0;k<a.length;k++){var l=a[k];for(e in l)l.hasOwnProperty(e)&&c(this,l,e)}else for(e in a)a.hasOwnProperty(e)&&c(this,a,e);return f?q(g):this}function p(a){var b,c={};if(a&&a.deep)for(b in this)this.hasOwnProperty(b)&&(c[b]=m(this[b]));else for(b in this)this.hasOwnProperty(b)&&(c[b]=this[b]);return c}function q(b){return a(b,"merge",o),a(b,"without",j),a(b,"asMutable",p),f(b,t)}function r(a){if(arguments.length>1)return h(Array.prototype.slice.call(arguments));if(c(a))return a;if(a instanceof Array)return h(a.slice());if(a instanceof Date)return f(new Date(a.getTime()));var b={};for(var d in a)a.hasOwnProperty(d)&&(b[d]=r(a[d]));return q(b)}var s="__immutable_invariants_hold",t=["setPrototypeOf"],u=["keys"],v=t.concat(["push","pop","sort","splice","shift","unshift","reverse"]),w=u.concat(["map","filter","slice","concat","reduce","reduceRight"]);e.prototype=Error.prototype,r.isImmutable=c,r.ImmutableError=e,Object.freeze(r),"object"==typeof module?module.exports=r:"object"==typeof exports?exports.Immutable=r:"object"==typeof window?window.Immutable=r:"object"==typeof global&&(global.Immutable=r)}();
\ No newline at end of file
+!function(){"use strict";function a(a,b,c){Object.defineProperty(a,b,{enumerable:!1,configurable:!1,writable:!1,value:c})}function b(b){a(b,s,!0)}function c(a){return"object"==typeof a?null===a||a.hasOwnProperty(s):!0}function d(a){return!(null===a||"object"!=typeof a||a instanceof Array||a instanceof Date)}function e(a){var b=new Error(a);return b.__proto__=e,b}function f(a,c){b(a);return a}function g(b,c){var d=b[c];a(b,c,function(){return r(d.apply(b,arguments))})}function h(b){for(var c in w)if(w.hasOwnProperty(c)){var d=w[c];g(b,d)}a(b,"flatMap",i),a(b,"asObject",l),a(b,"asMutable",k);for(var e=0,h=b.length;h>e;e++)b[e]=r(b[e]);return f(b,v)}function i(a){if(0===arguments.length)return this;var b,c=[],d=this.length;for(b=0;d>b;b++){var e=a(this[b],b,this);e instanceof Array?c.push.apply(c,e):c.push(e)}return h(c)}function j(a){if(0===arguments.length)return this;a instanceof Array||(a=Array.prototype.slice.call(arguments));var b={};for(var c in this)this.hasOwnProperty(c)&&-1===a.indexOf(c)&&(b[c]=this[c]);return q(b)}function k(a){var b,c,d=[];if(a&&a.deep)for(b=0,c=this.length;c>b;b++)d.push(m(this[b]));else for(b=0,c=this.length;c>b;b++)d.push(this[b]);return d}function l(a){"function"!=typeof a&&(a=function(a){return a});var b,c={},d=this.length;for(b=0;d>b;b++){var e=a(this[b],b,this),f=e[0],g=e[1];c[f]=g}return q(c)}function m(a){return a instanceof Date||!a||!a.hasOwnProperty(s)?a:a.asMutable({deep:!0})}function n(a,b){for(var c in a)a.hasOwnProperty(c)&&(b[c]=a[c]);return b}function o(a,b){function c(a,c,e){var h=r(c[e]),k=j&&j(a[e],h,b);j&&k&&k===a[e]||(f=f||void 0!==k||!a.hasOwnProperty(e)||h!==a[e]&&h===h,g[e]=k?k:i&&d(a[e])&&d(h)?a[e].merge(h,b):h)}if(0===arguments.length)return this;if(null===a||"object"!=typeof a)throw new TypeError("Immutable#merge can only be invoked with objects or arrays, not "+JSON.stringify(a));var e,f=!1,g=n(this,{}),h=a instanceof Array,i=b&&b.deep,j=b&&b.merger;if(h)for(var k=0;k<a.length;k++){var l=a[k];for(e in l)l.hasOwnProperty(e)&&c(this,l,e)}else for(e in a)a.hasOwnProperty(e)&&c(this,a,e);return f?q(g):this}function p(a){var b,c={};if(a&&a.deep)for(b in this)this.hasOwnProperty(b)&&(c[b]=m(this[b]));else for(b in this)this.hasOwnProperty(b)&&(c[b]=this[b]);return c}function q(b){return a(b,"merge",o),a(b,"without",j),a(b,"asMutable",p),f(b,t)}function r(a){if(arguments.length>1)return h(Array.prototype.slice.call(arguments));if(c(a))return a;if(a instanceof Array)return h(a.slice());if(a instanceof Date)return f(new Date(a.getTime()));var b={};for(var d in a)a.hasOwnProperty(d)&&(b[d]=r(a[d]));return q(b)}var s="__immutable_invariants_hold",t=["setPrototypeOf"],u=["keys"],v=t.concat(["push","pop","sort","splice","shift","unshift","reverse"]),w=u.concat(["map","filter","slice","concat","reduce","reduceRight"]);e.prototype=Error.prototype,r.isImmutable=c,r.ImmutableError=e,Object.freeze(r),"object"==typeof module?module.exports=r:"object"==typeof exports?exports.Immutable=r:"object"==typeof window?window.Immutable=r:"object"==typeof global&&(global.Immutable=r)}();
\ No newline at end of file
diff --git a/src/seamless-immutable.js b/src/seamless-immutable.js
index de6d7ab..aa602c0 100644
--- a/src/seamless-immutable.js
+++ b/src/seamless-immutable.js
@@ -214,7 +214,7 @@
   }
 
   function asDeepMutable(obj) {
-    if( !obj || !obj.hasOwnProperty(immutabilityTag) ) { return obj; }
+    if(!obj || !obj.hasOwnProperty(immutabilityTag) || obj instanceof Date) { return obj; }
     return obj.asMutable({deep: true});
   }
 


Test patch:
diff --git a/test/ImmutableObject/test-asMutable.js b/test/ImmutableObject/test-asMutable.js
index b19f473..f76d759 100644
--- a/test/ImmutableObject/test-asMutable.js
+++ b/test/ImmutableObject/test-asMutable.js
@@ -30,5 +30,12 @@ module.exports = function(config) {
         assert.deepEqual(immutable,mutable);
       });
     });
+
+      it("does not throw an error when asMutable deep = true is called on an Immutable with a nested date", function() {
+          check(100, [ TestUtils.TraversableObjectSpecifier ], function(obj) {
+              var test = Immutable({ testDate: new Date()});
+              test.asMutable({deep: true});
+          });
+      });
   });
 };