From 7e1113561ac60f376b154f430ec79a212e22cc75 Mon Sep 17 00:00:00 2001 From: Adam Wathan Date: Fri, 22 Mar 2019 12:47:14 -0400 Subject: [PATCH] Don't mutate the user's config when resolving --- __tests__/resolveConfig.test.js | 40 +++++++++++++++++++++++++++++++++ src/util/resolveConfig.js | 2 +- 2 files changed, 41 insertions(+), 1 deletion(-) diff --git a/__tests__/resolveConfig.test.js b/__tests__/resolveConfig.test.js index f1e13a2a4..e75b47b79 100644 --- a/__tests__/resolveConfig.test.js +++ b/__tests__/resolveConfig.test.js @@ -826,3 +826,43 @@ test('theme values in the extend section are lazily evaluated', () => { }, }) }) + +test('the original theme is not mutated', () => { + const userConfig = { + theme: { + extend: { + colors: { + orange: 'orange', + }, + }, + }, + } + + const defaultConfig = { + prefix: '-', + important: false, + separator: ':', + theme: { + colors: { + cyan: 'cyan', + magenta: 'magenta', + yellow: 'yellow', + }, + }, + variants: { + borderColor: ['responsive', 'hover', 'focus'], + }, + } + + resolveConfig([userConfig, defaultConfig]) + + expect(userConfig).toEqual({ + theme: { + extend: { + colors: { + orange: 'orange', + }, + }, + }, + }) +}) diff --git a/src/util/resolveConfig.js b/src/util/resolveConfig.js index 0db03c222..10eefc0ef 100644 --- a/src/util/resolveConfig.js +++ b/src/util/resolveConfig.js @@ -38,7 +38,7 @@ function resolveFunctionKeys(object) { export default function resolveConfig(configs) { return defaults( { - theme: resolveFunctionKeys(mergeExtensions(defaults(...map(configs, 'theme')))), + theme: resolveFunctionKeys(mergeExtensions(defaults({}, ...map(configs, 'theme')))), variants: defaults(...map(configs, 'variants')), }, ...configs