From d679ab8b72fde3c537dfb31842034fe23ff9cef6 Mon Sep 17 00:00:00 2001 From: Dragory <2606411+Dragory@users.noreply.github.com> Date: Sun, 4 Aug 2019 17:30:47 +0300 Subject: [PATCH] Temporary fixes to deepKeyIntersect while config modifiers are still a thing --- src/utils.ts | 28 +++++++++++++++++++++++++--- 1 file changed, 25 insertions(+), 3 deletions(-) diff --git a/src/utils.ts b/src/utils.ts index 832484b9..aca89a6e 100644 --- a/src/utils.ts +++ b/src/utils.ts @@ -582,11 +582,33 @@ export function isObjectLiteral(obj) { return Object.getPrototypeOf(obj) === deepestPrototype; } +const keyMods = ["+", "-", "="]; export function deepKeyIntersect(obj, keyReference) { const result = {}; - for (const [key, value] of Object.entries(obj)) { - if (!keyReference.hasOwnProperty(key)) continue; - if (value != null && typeof value === "object" && typeof keyReference[key] === "object" && isObjectLiteral(value)) { + for (let [key, value] of Object.entries(obj)) { + if (!keyReference.hasOwnProperty(key)) { + // Temporary solution so we don't erase keys with modifiers + // Modifiers will be removed soon(tm) so we can remove this when that happens as well + let found = false; + for (const mod of keyMods) { + if (keyReference.hasOwnProperty(mod + key)) { + key = mod + key; + found = true; + break; + } + } + if (!found) continue; + } + + if (Array.isArray(value)) { + // Also temp (because modifier shenanigans) + result[key] = keyReference[key]; + } else if ( + value != null && + typeof value === "object" && + typeof keyReference[key] === "object" && + isObjectLiteral(value) + ) { result[key] = deepKeyIntersect(value, keyReference[key]); } else { result[key] = value;