File tree Expand file tree Collapse file tree 5 files changed +38
-5
lines changed Expand file tree Collapse file tree 5 files changed +38
-5
lines changed Original file line number Diff line number Diff line change
1
+ {
2
+ "releases" : [{ "name" : " @emotion/serialize" , "type" : " patch" }],
3
+ "dependents" : []
4
+ }
Original file line number Diff line number Diff line change
1
+ Fixed issue with camelCased custom properties not being handled correctly in object styles
Original file line number Diff line number Diff line change @@ -36,6 +36,17 @@ exports[`css call composition 1`] = `
36
36
/>
37
37
` ;
38
38
39
+ exports [` handles camelCased custom properties in object styles properly 1` ] = `
40
+ .emotion-0 {
41
+ -- textColor : green ;
42
+ color : var (-- textColor );
43
+ }
44
+
45
+ <div
46
+ className = " emotion-0"
47
+ />
48
+ ` ;
49
+
39
50
exports [` label in css call 1` ] = `
40
51
.emotion-0 {
41
52
color : hotpink ;
Original file line number Diff line number Diff line change @@ -188,3 +188,16 @@ test('child selector array', () => {
188
188
189
189
expect ( tree . toJSON ( ) ) . toMatchSnapshot ( )
190
190
} )
191
+
192
+ test ( 'handles camelCased custom properties in object styles properly' , ( ) => {
193
+ const tree = renderer . create (
194
+ < div
195
+ css = { {
196
+ '--textColor' : 'green' ,
197
+ color : 'var(--textColor)'
198
+ } }
199
+ />
200
+ )
201
+
202
+ expect ( tree . toJSON ( ) ) . toMatchSnapshot ( )
203
+ } )
Original file line number Diff line number Diff line change @@ -11,8 +11,13 @@ import memoize from '@emotion/memoize'
11
11
let hyphenateRegex = / [ A - Z ] | ^ m s / g
12
12
let animationRegex = / _ E M O _ ( [ ^ _ ] + ?) _ ( [ ^ ] * ?) _ E M O _ / g
13
13
14
- const processStyleName = memoize ( ( styleName : string ) =>
15
- styleName . replace ( hyphenateRegex , '-$&' ) . toLowerCase ( )
14
+ const isCustomProperty = ( property : string ) => property . charCodeAt ( 1 ) === 45
15
+
16
+ const processStyleName = memoize (
17
+ ( styleName : string ) =>
18
+ isCustomProperty ( styleName )
19
+ ? styleName
20
+ : styleName . replace ( hyphenateRegex , '-$&' ) . toLowerCase ( )
16
21
)
17
22
18
23
let processStyleValue = (
@@ -41,7 +46,7 @@ let processStyleValue = (
41
46
42
47
if (
43
48
unitless [ key ] !== 1 &&
44
- key . charCodeAt ( 1 ) !== 45 && // custom properties
49
+ ! isCustomProperty ( key ) &&
45
50
typeof value === 'number' &&
46
51
value !== 0
47
52
) {
@@ -88,11 +93,10 @@ if (process.env.NODE_ENV !== 'production') {
88
93
}
89
94
90
95
const processed = oldProcessStyleValue ( key , value )
91
- const isCssVariable = key . charCodeAt ( 1 ) === 45
92
96
93
97
if (
94
98
processed !== '' &&
95
- ! isCssVariable &&
99
+ ! isCustomProperty ( key ) &&
96
100
key . indexOf ( '-' ) !== - 1 &&
97
101
hyphenatedCache [ key ] === undefined
98
102
) {
You can’t perform that action at this time.
0 commit comments