Skip to content

Commit 81c2463

Browse files
committed
release for version 0.6.3
2 parents c3734d9 + ee8a7d6 commit 81c2463

File tree

7 files changed

+68
-8
lines changed

7 files changed

+68
-8
lines changed

HISTORY.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
# 0.6.3 / 2016-06-13
2+
3+
- fixed #10, #11, #12
4+
15
# 0.6.2 / 2016-06-12
26

37
- fixed #10

build/deepcopy.js

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ return /******/ (function(modules) { // webpackBootstrap
159159
var resultValue = copyValue(target);
160160

161161
if (resultValue !== null) {
162-
return copyValue(target);
162+
return resultValue;
163163
}
164164

165165
return copyCollection(target, customizer);
@@ -361,15 +361,17 @@ return /******/ (function(modules) { // webpackBootstrap
361361
value = target[key];
362362
index = (0, _polyfill.indexOf)(visited, value);
363363

364+
resultCopy = void 0;
365+
result = void 0;
366+
ref = void 0;
367+
364368
if (index === -1) {
365369
resultCopy = (0, _copy.copy)(value, customizer);
366370
result = resultCopy !== null ? resultCopy : value;
367371

368372
if (value !== null && /^(?:function|object)$/.test(typeof value)) {
369373
visited.push(value);
370374
reference.push(result);
371-
} else {
372-
ref = result;
373375
}
374376
} else {
375377
// circular reference

build/deepcopy.min.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "deepcopy",
3-
"version": "0.6.2",
3+
"version": "0.6.3",
44
"author": "sasa+1 <[email protected]>",
55
"contributors": [
66
"kjirou <[email protected]>"

src/copy.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ function copy(target, customizer) {
66
const resultValue = copyValue(target);
77

88
if (resultValue !== null) {
9-
return copyValue(target);
9+
return resultValue;
1010
}
1111

1212
return copyCollection(target, customizer);

src/index.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,15 +61,17 @@ function recursiveCopy(target, customizer, clone, visited, reference) {
6161
value = target[key];
6262
index = indexOf(visited, value);
6363

64+
resultCopy = undefined;
65+
result = undefined;
66+
ref = undefined;
67+
6468
if (index === -1) {
6569
resultCopy = copy(value, customizer);
6670
result = (resultCopy !== null) ? resultCopy : value;
6771

6872
if (value !== null && /^(?:function|object)$/.test(typeof value)) {
6973
visited.push(value);
7074
reference.push(result);
71-
} else {
72-
ref = result;
7375
}
7476
} else {
7577
// circular reference

test/index.js

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -385,6 +385,58 @@ describe('deepcopy', function() {
385385
assert(functionInArrayInArray.a[1][1] === copiedFunctionInArrayInArray.a[1][1]);
386386
});
387387

388+
it('can copy deeper Object and Array', function() {
389+
const array = [
390+
1,
391+
2,
392+
[
393+
3,
394+
4,
395+
[
396+
function() {},
397+
6,
398+
7
399+
]
400+
]
401+
];
402+
403+
const copiedArray = deepcopy(array);
404+
405+
assert(array !== copiedArray);
406+
assert(array[0] === copiedArray[0]);
407+
assert(array[1] === copiedArray[1]);
408+
assert(array[2] !== copiedArray[2]);
409+
assert(array[2][0] === copiedArray[2][0]);
410+
assert(array[2][1] === copiedArray[2][1]);
411+
assert(array[2][2] !== copiedArray[2][2]);
412+
assert(array[2][2][0] !== copiedArray[2][2][0]);
413+
assert(array[2][2][1] === copiedArray[2][2][1]);
414+
assert(array[2][2][2] === copiedArray[2][2][2]);
415+
416+
const object = {
417+
a: 'a',
418+
b: 'b',
419+
c: {
420+
d: function() {},
421+
e: {
422+
f: 'f',
423+
g: 'g'
424+
}
425+
}
426+
};
427+
428+
const copiedObject = deepcopy(object);
429+
430+
assert(object !== copiedObject);
431+
assert(object.a === copiedObject.a);
432+
assert(object.b === copiedObject.b);
433+
assert(object.c !== copiedObject.c);
434+
assert(object.c.d !== copiedObject.c.d);
435+
assert(object.c.e !== copiedObject.c.e);
436+
assert(object.c.e.f === copiedObject.c.e.f);
437+
assert(object.c.e.g === copiedObject.c.e.g);
438+
});
439+
388440
it('can copy Class from Array and Object by customizer', function() {
389441
function MyClass(number) {
390442
this.number = +number;

0 commit comments

Comments
 (0)