Skip to content

Commit 43146fc

Browse files
authored
Merge pull request #685 from rofrischmann/extend-all-extensions
Improve fela-plugin-extend
2 parents d69af0d + e9af7b7 commit 43146fc

2 files changed

Lines changed: 89 additions & 1 deletion

File tree

packages/fela-plugin-extend/src/__tests__/extend-test.js

Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,94 @@ describe('Extend plugin', () => {
143143
})
144144
})
145145

146+
it('should merge multiple nested extensions', () => {
147+
const base = {
148+
color: 'blue',
149+
backgroundColor: 'red',
150+
extend: {
151+
color: 'green',
152+
fontSize: 15,
153+
extend: {
154+
lineHeight: 1.0,
155+
},
156+
},
157+
}
158+
159+
expect(extend()(base)).toEqual({
160+
color: 'blue',
161+
backgroundColor: 'red',
162+
color: 'green',
163+
fontSize: 15,
164+
lineHeight: 1.0,
165+
})
166+
})
167+
168+
it('should merge multiple nested conditional extensions', () => {
169+
const base = {
170+
color: 'blue',
171+
backgroundColor: 'red',
172+
extend: {
173+
condition: true,
174+
style: {
175+
color: 'green',
176+
fontSize: 15,
177+
extend: {
178+
condition: true,
179+
style: {
180+
lineHeight: 1.0,
181+
},
182+
},
183+
},
184+
},
185+
}
186+
187+
expect(extend()(base)).toEqual({
188+
color: 'blue',
189+
backgroundColor: 'red',
190+
color: 'green',
191+
fontSize: 15,
192+
lineHeight: 1.0,
193+
})
194+
})
195+
196+
it('should merge multiple nested conditional extensions', () => {
197+
const base = {
198+
color: 'blue',
199+
backgroundColor: 'red',
200+
extend: [
201+
{
202+
condition: true,
203+
style: {
204+
color: 'green',
205+
fontSize: 15,
206+
extend: {
207+
condition: true,
208+
style: {
209+
lineHeight: 1.0,
210+
},
211+
},
212+
},
213+
},
214+
{
215+
paddingLeft: 10,
216+
extend: {
217+
paddingRight: 10,
218+
},
219+
},
220+
],
221+
}
222+
223+
expect(extend()(base)).toEqual({
224+
color: 'blue',
225+
backgroundColor: 'red',
226+
color: 'green',
227+
fontSize: 15,
228+
lineHeight: 1.0,
229+
paddingLeft: 10,
230+
paddingRight: 10,
231+
})
232+
})
233+
146234
it('should not convert null values to empty objects', () => {
147235
const base = {
148236
color: 'blue',

packages/fela-plugin-extend/src/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ function extendStyle(style: Object, extension: Object): void {
3232
}
3333
} else {
3434
// extend basic style objects
35-
assignStyle(style, removeUndefined(extension))
35+
assignStyle(style, removeUndefined(extend(extension)))
3636
}
3737
}
3838

0 commit comments

Comments
 (0)