Skip to content

Commit 6da7d69

Browse files
committed
Fix the issue #3
1 parent e7b3ef6 commit 6da7d69

File tree

6 files changed

+37
-4
lines changed

6 files changed

+37
-4
lines changed

.npmrc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
package-lock=false

index.js

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -186,9 +186,15 @@ function _setDeep(obj, keyElems, depth, valueCreator) {
186186
var key = keyElems.shift();
187187
if (!keyElems.length) {
188188
var value = valueCreator(obj, key, depth);
189-
if (value !== undefined) {
190-
obj[key] = value;
189+
if (value === undefined) {
190+
return;
191+
}
192+
if (isObject(value)) { // value is always an empty object.
193+
if (isObject(obj[key])) {
194+
return;
195+
}
191196
}
197+
obj[key] = value;
192198
return;
193199
}
194200

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
"test": "mocha",
1212
"coverage": "istanbul cover _mocha",
1313
"coveralls": "istanbul cover _mocha && istanbul-coveralls",
14-
"web:install": "npm i phantomjs-prebuilt mocha-phantomjs",
14+
"web:install": "npm install --no-save phantomjs-prebuilt mocha-phantomjs",
1515
"web:build": "browserify index.js --standalone copyProps | uglifyjs --compress --mangle -o web/copy-props.js && node test/web/make.js",
1616
"web:test": "mocha-phantomjs -p node_modules/.bin/phantomjs test/web/copy-props.test.html"
1717
},

test/copy-props-proc.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,12 @@ describe('Processing', function() {
160160
done();
161161
});
162162

163+
it('Should do nothing when src prop is an empty object and dst is an ' +
164+
'object', function() {
165+
var src = { a: { b: {} } };
166+
var dst = { a: { b: { c: 1 } } };
167+
expect(copyProps(src, dst)).to.deep.equal({ a: { b: { c: 1 } } });
168+
});
163169
});
164170

165171
describe('About fromto special cases', function() {
@@ -249,6 +255,13 @@ describe('Processing', function() {
249255
done();
250256
});
251257

258+
it('Should do nothing when src prop is an empty object and dst is an ' +
259+
'object', function() {
260+
var src = { a: { b: {} } };
261+
var dst = { a: { b: { c: 1 } } };
262+
var fromto = ['a.b'];
263+
expect(copyProps(src, dst, fromto)).to.deep.equal({ a: { b: { c: 1 } } });
264+
});
252265
});
253266

254267
describe('About patterns of converter returns', function() {

test/web/copy-props-proc.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,12 @@ describe('Processing', function() {
160160
done();
161161
});
162162

163+
it('Should do nothing when src prop is an empty object and dst is an ' +
164+
'object', function() {
165+
var src = { a: { b: {} } };
166+
var dst = { a: { b: { c: 1 } } };
167+
expect(copyProps(src, dst)).to.deep.equal({ a: { b: { c: 1 } } });
168+
});
163169
});
164170

165171
describe('About fromto special cases', function() {
@@ -249,6 +255,13 @@ describe('Processing', function() {
249255
done();
250256
});
251257

258+
it('Should do nothing when src prop is an empty object and dst is an ' +
259+
'object', function() {
260+
var src = { a: { b: {} } };
261+
var dst = { a: { b: { c: 1 } } };
262+
var fromto = ['a.b'];
263+
expect(copyProps(src, dst, fromto)).to.deep.equal({ a: { b: { c: 1 } } });
264+
});
252265
});
253266

254267
describe('About patterns of converter returns', function() {

web/copy-props.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.

0 commit comments

Comments
 (0)