File tree 5 files changed +64
-3
lines changed
5 files changed +64
-3
lines changed Original file line number Diff line number Diff line change
1
+ ---
2
+ ' @emotion/serialize ' : patch
3
+ ---
4
+
5
+ Warn about ` undefined ` being used as object style's key
Original file line number Diff line number Diff line change @@ -23,10 +23,25 @@ Array [
23
23
]
24
24
` ;
25
25
26
+ exports [` array fallback (using camelCased property) 1` ] = `
27
+ .emotion-0 {
28
+ background - color : green ;
29
+ background - color : hotpink ;
30
+ }
31
+
32
+ <div >
33
+ <div
34
+ className = " emotion-0"
35
+ >
36
+ something
37
+ </div >
38
+ </div >
39
+ ` ;
40
+
26
41
exports [` array fallback 1` ] = `
27
42
.emotion-0 {
28
- display : green ;
29
- display : hotpink ;
43
+ color : green ;
44
+ color : hotpink ;
30
45
}
31
46
32
47
<div >
Original file line number Diff line number Diff line change @@ -102,7 +102,23 @@ test('array fallback', () => {
102
102
< div >
103
103
< div
104
104
css = { {
105
- display : [ 'green' , 'hotpink' ]
105
+ color : [ 'green' , 'hotpink' ]
106
+ } }
107
+ >
108
+ something
109
+ </ div >
110
+ </ div >
111
+ )
112
+
113
+ expect ( tree . toJSON ( ) ) . toMatchSnapshot ( )
114
+ } )
115
+
116
+ test ( 'array fallback (using camelCased property)' , ( ) => {
117
+ const tree = renderer . create (
118
+ < div >
119
+ < div
120
+ css = { {
121
+ backgroundColor : [ 'green' , 'hotpink' ]
106
122
} }
107
123
>
108
124
something
Original file line number Diff line number Diff line change @@ -13,6 +13,9 @@ Because you write your CSS inside a JavaScript string you actually have to do do
13
13
You can read more about this here:
14
14
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Template_literals#ES2018_revision_of_illegal_escape_sequences`
15
15
16
+ const UNDEFINED_AS_OBJECT_KEY_ERROR =
17
+ "You have passed in falsy value as style object's key (can happen when in example you pass unexported component as computed key)."
18
+
16
19
let hyphenateRegex = / [ A - Z ] | ^ m s / g
17
20
let animationRegex = / _ E M O _ ( [ ^ _ ] + ?) _ ( [ ^ ] * ?) _ E M O _ / g
18
21
@@ -308,6 +311,12 @@ function createStringFromObject(
308
311
break
309
312
}
310
313
default : {
314
+ if (
315
+ process . env . NODE_ENV !== 'production' &&
316
+ key === 'undefined'
317
+ ) {
318
+ console . error ( UNDEFINED_AS_OBJECT_KEY_ERROR )
319
+ }
311
320
string += `${ key } {${ interpolated } }`
312
321
}
313
322
}
Original file line number Diff line number Diff line change 1
1
// @flow
2
2
import 'test-utils/legacy-env'
3
+ import * as React from 'react'
3
4
import { css } from '@emotion/core'
4
5
import styled from '@emotion/styled'
6
+ import { render } from '@testing-library/react'
5
7
6
8
// $FlowFixMe
7
9
console . error = jest . fn ( )
@@ -48,3 +50,17 @@ it('warns about illegal escape sequences inside non-first quasi of template lite
48
50
]
49
51
` )
50
52
} )
53
+
54
+ it ( "warns about undefined being passed as object style's key" , ( ) => {
55
+ let ListItem
56
+ // $FlowFixMe
57
+ const List = styled . ul ( { [ ListItem ] : { color : 'hotpink' } } )
58
+
59
+ render ( < List /> )
60
+
61
+ expect ( ( console . error : any ) . mock . calls [ 0 ] ) . toMatchInlineSnapshot ( `
62
+ Array [
63
+ "You have passed in falsy value as style object's key (can happen when in example you pass unexported component as computed key).",
64
+ ]
65
+ ` )
66
+ } )
You can’t perform that action at this time.
0 commit comments