File tree Expand file tree Collapse file tree 2 files changed +42
-9
lines changed
Expand file tree Collapse file tree 2 files changed +42
-9
lines changed Original file line number Diff line number Diff line change @@ -294,7 +294,7 @@ test("@prop multiple", () => {
294294 } ) ;
295295} ) ;
296296
297- test ( "@prop dot notation" , ( ) => {
297+ test ( "@prop dot notation shorthand " , ( ) => {
298298 const compiled = registerCSS ( `
299299 .my-class {
300300 @prop test.nested;
@@ -331,3 +331,41 @@ test("@prop dot notation", () => {
331331 testID : "react-native-css" ,
332332 } ) ;
333333} ) ;
334+
335+ test ( "@prop dot notation, escaped" , ( ) => {
336+ const compiled = registerCSS ( `
337+ .my-class {
338+ @prop test\\.nested;
339+ @media all {
340+ color: red;
341+ }
342+ }
343+ ` ) ;
344+
345+ expect ( compiled . stylesheet ( ) ) . toStrictEqual ( {
346+ s : [
347+ [
348+ "my-class" ,
349+ [
350+ {
351+ d : [ [ "#f00" , [ "test" , "nested" ] ] ] ,
352+ v : [ [ "__rn-css-color" , "#f00" ] ] ,
353+ s : [ 2 , 1 ] ,
354+ } ,
355+ ] ,
356+ ] ,
357+ ] ,
358+ } ) ;
359+
360+ render ( < View testID = { testID } className = "my-class" /> ) ;
361+ const component = screen . getByTestId ( testID ) ;
362+
363+ expect ( component . props ) . toStrictEqual ( {
364+ children : undefined ,
365+ style : { } ,
366+ test : {
367+ nested : "#f00" ,
368+ } ,
369+ testID : "react-native-css" ,
370+ } ) ;
371+ } ) ;
Original file line number Diff line number Diff line change @@ -108,7 +108,7 @@ function propAtRuleBlock(
108108 } ) ;
109109
110110 // @props <to>; (has no from value)
111- if ( ! to && from ) {
111+ if ( ! to ) {
112112 to = from ;
113113 from = [
114114 {
@@ -119,7 +119,7 @@ function propAtRuleBlock(
119119 }
120120
121121 // We can only map from a single property
122- if ( ! from || from . length !== 1 ) {
122+ if ( ! from || from . length !== 1 || ! to ) {
123123 return mapping ;
124124 }
125125
@@ -128,17 +128,12 @@ function propAtRuleBlock(
128128 return mapping ;
129129 }
130130
131- if ( ! to ) {
132- mapping [ "*" ] = toRNProperty ( fromToken . value . value ) ;
133- return mapping ;
134- }
135-
136131 mapping [ toRNProperty ( fromToken . value . value ) ] = to . flatMap ( ( item , index ) => {
137132 switch ( item . value . type ) {
138133 case "delim" :
139134 return index === 0 && item . value . value === "*" ? [ "*" ] : [ ] ;
140135 case "ident" :
141- return [ toRNProperty ( item . value . value ) ] ;
136+ return item . value . value . split ( "." ) . map ( ( part ) => toRNProperty ( part ) ) ;
142137 default :
143138 return [ ] ;
144139 }
You can’t perform that action at this time.
0 commit comments