Skip to content

Commit

Permalink
fix(extend): multiple extensions properly deep merge (#276)
Browse files Browse the repository at this point in the history
Fixes #274
  • Loading branch information
dbanksdesign authored and chazzmoney committed May 21, 2019
1 parent 334ea54 commit f1d6bb0
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
18 changes: 18 additions & 0 deletions __tests__/extend.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');
});
});
2 changes: 1 addition & 1 deletion lib/extend.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down

0 comments on commit f1d6bb0

Please sign in to comment.