From 75401227cab476cd82be0a26e21c40d2a4360b32 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marcos=20Susa=C3=B1a?= Date: Thu, 29 Jun 2023 01:41:09 -0400 Subject: [PATCH] fix(common): Options merge side effect --- packages/common/src/Util.ts | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/packages/common/src/Util.ts b/packages/common/src/Util.ts index ae497c9..09f8f42 100644 --- a/packages/common/src/Util.ts +++ b/packages/common/src/Util.ts @@ -23,25 +23,28 @@ export const Options = (defaults: any, ...options: any[]): T => { const source = options.shift(); - if (isObject(defaults) && isPlainObject(source)) { + // This prevents default options from being intercepted by `Object.assign` + const $ = { ...defaults }; + + if (isObject($) && isPlainObject(source)) { Object.entries(source).forEach(([key, value]) => { if (typeof value === 'undefined') { return; } if (isPlainObject(value)) { - if (!(key in defaults)) { - Object.assign(defaults, { [key]: {} }); + if (!(key in $)) { + Object.assign($, { [key]: {} }); } - Options(defaults[key], value); + Options($[key], value); } else { - Object.assign(defaults, { [key]: value }); + Object.assign($, { [key]: value }); } }); } - return Options(defaults, ...options); + return Options($, ...options); }; /** * Convert a camelCase object to snake_case.