From b2214a843db312eb26fc085bb5f399dab488400b Mon Sep 17 00:00:00 2001 From: wuhy Date: Mon, 24 Dec 2018 10:25:34 +0800 Subject: [PATCH] fix(okam-build): fix merge not plain object not correct #23 --- packages/okam-build/lib/util/index.js | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/packages/okam-build/lib/util/index.js b/packages/okam-build/lib/util/index.js index 0ce90cbc..3a63c897 100644 --- a/packages/okam-build/lib/util/index.js +++ b/packages/okam-build/lib/util/index.js @@ -7,6 +7,10 @@ const helper = require('okam-helper'); +function isPlainObject(obj) { + return toString.call(obj) === '[object Object]'; +} + function doMerge(target, source, selector, doNotMergeSelectors) { if (doNotMergeSelectors && doNotMergeSelectors.includes(selector)) { return source; @@ -24,8 +28,8 @@ function doMerge(target, source, selector, doNotMergeSelectors) { return result; } - let isTargetObj = !isTargetArr && target && typeof target === 'object'; - let isSourceObj = !isSourceArr && source && typeof source === 'object'; + let isTargetObj = !isTargetArr && isPlainObject(target); + let isSourceObj = !isSourceArr && isPlainObject(source); if (isTargetObj && isSourceObj) { let result = Object.assign({}, target); Object.keys(source).forEach(k => {