diff --git a/__tests__/extend.test.js b/__tests__/extend.test.js index 7434108ef..c9ca204dd 100644 --- a/__tests__/extend.test.js +++ b/__tests__/extend.test.js @@ -171,4 +171,22 @@ describe('extend', () => { var StyleDictionaryExtended = StyleDictionary.extend(__dirname + '/__configs/test.json5'); expect(StyleDictionaryExtended).toHaveProperty('platforms.web'); }); + + it('should allow for chained extends and not mutate the original', function() { + var StyleDictionary1 = StyleDictionary.extend({ + foo: 'bar' + }); + var StyleDictionary2 = StyleDictionary1.extend({ + foo: 'baz' + }); + var StyleDictionary3 = StyleDictionary.extend({ + foo: 'bar' + }).extend({ + foo: 'boo' + }); + expect(StyleDictionary1.foo).toBe('bar'); + expect(StyleDictionary2.foo).toBe('baz'); + expect(StyleDictionary3.foo).toBe('boo'); + expect(StyleDictionary).not.toHaveProperty('foo'); + }); }); diff --git a/lib/extend.js b/lib/extend.js index 7b94bb91d..ece6f97ee 100644 --- a/lib/extend.js +++ b/lib/extend.js @@ -96,7 +96,7 @@ function extend(opts) { // Creating a new object and copying over the options // Also keeping an options object just in case - to_ret = deepExtend([{options: options}, this, options]); + to_ret = deepExtend([{}, this, {options: options}, options]); // Update properties with includes from dependencies if (options.include) {