@@ -199,43 +199,52 @@ function normalizeColor(value: string | object) {
199
199
}
200
200
201
201
export default function expand (
202
- style : Record < string , string | number > ,
202
+ style : Record < string , string | number > | undefined ,
203
203
inheritedStyle : Record < string , string | number >
204
204
) : Record < string , string | number > {
205
205
const transformedStyle = { } as any
206
206
207
- for ( const prop in style ) {
208
- // Internal properties.
209
- if ( prop . startsWith ( '_' ) ) {
210
- transformedStyle [ prop ] = style [ prop ]
211
- continue
212
- }
207
+ if ( style ) {
208
+ const currentColor = getCurrentColor ( style . color as string , inheritedStyle . color as string )
213
209
214
- const name = getPropertyName ( prop )
215
- const currentColor = ( style . color || inheritedStyle . color ) as string
210
+ transformedStyle . color = currentColor
216
211
217
- try {
218
- const resolvedStyle =
219
- handleSpecialCase ( name , style [ prop ] , currentColor ) ||
220
- handleFallbackColor (
221
- name ,
222
- getStylesForProperty ( name , purify ( name , style [ prop ] ) , true ) ,
223
- style [ prop ] as string ,
224
- currentColor
225
- )
212
+ for ( const prop in style ) {
213
+ // Internal properties.
214
+ if ( prop . startsWith ( '_' ) ) {
215
+ transformedStyle [ prop ] = style [ prop ]
216
+ continue
217
+ }
226
218
227
- Object . assign ( transformedStyle , resolvedStyle )
228
- } catch ( err ) {
229
- throw new Error (
230
- err . message +
219
+ if ( prop === 'color' ) {
220
+ continue
221
+ }
222
+
223
+ const name = getPropertyName ( prop )
224
+
225
+ try {
226
+ const resolvedStyle =
227
+ handleSpecialCase ( name , style [ prop ] , currentColor ) ||
228
+ handleFallbackColor (
229
+ name ,
230
+ getStylesForProperty ( name , purify ( name , style [ prop ] ) , true ) ,
231
+ style [ prop ] as string ,
232
+ currentColor
233
+ )
234
+
235
+ Object . assign ( transformedStyle , resolvedStyle )
236
+ } catch ( err ) {
237
+ throw new Error (
238
+ err . message +
231
239
// Attach the extra information of the rule itself if it's not included in
232
240
// the error message.
233
241
( err . message . includes ( style [ prop ] )
234
242
? '\n ' + getErrorHint ( name )
235
243
: `\n in CSS rule \`${ name } : ${ style [ prop ] } \`.${ getErrorHint (
236
- name
237
- ) } `)
238
- )
244
+ name
245
+ ) } `)
246
+ )
247
+ }
239
248
}
240
249
}
241
250
@@ -337,3 +346,11 @@ export default function expand(
337
346
338
347
return transformedStyle
339
348
}
349
+
350
+ function getCurrentColor ( color : string | undefined , inheritedColor : string ) {
351
+ if ( color && color . toLowerCase ( ) !== 'currentcolor' ) {
352
+ return color
353
+ }
354
+
355
+ return inheritedColor
356
+ }
0 commit comments