Skip to content

Instantly share code, notes, and snippets.

@ciaranj
Created March 8, 2010 20:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ciaranj/325521 to your computer and use it in GitHub Desktop.
Save ciaranj/325521 to your computer and use it in GitHub Desktop.
diff --git a/src/node.js b/src/node.js
index afc70bf..8417460 100644
--- a/src/node.js
+++ b/src/node.js
@@ -138,11 +138,10 @@ process.mixin = function() {
if (target === d.value) {
continue;
}
-
if (deep && d.value && typeof d.value === "object") {
target[k] = process.mixin(deep,
// Never move original objects, clone them
- source[k] || (d.value.length != null ? [] : {})
+ target[k] || (d.value.length != null ? [] : {})
, d.value);
}
else {
diff --git a/test/simple/test-process-mixin.js b/test/simple/test-process-mixin.js
index ca7bf95..87bbc75 100644
--- a/test/simple/test-process-mixin.js
+++ b/test/simple/test-process-mixin.js
@@ -43,4 +43,13 @@ process.mixin(true, target, {
});
assert.notStrictEqual(['bar'], target.foo);
-assert.deepEqual(['bar'], target.foo);
\ No newline at end of file
+assert.deepEqual(['bar'], target.foo);
+
+// Test that nested literals are handled properly
+var sys= require('sys');
+var source= {a: 'x', b: {c:"d"}};
+var target= {b: {d:"e"}};
+var result= process.mixin(true, target, source);
+assert.equal(result.a, 'x')
+assert.equal(result.b.c, 'd')
+assert.equal(result.b.d, 'e')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment