@@ -915,7 +915,7 @@ export function parseUnparsedDeclaration(
915
915
builder . descriptorProperty = property ;
916
916
917
917
if ( unparsedRuntimeParsing . has ( property ) ) {
918
- const args = parseUnparsed ( declaration . value . value , builder ) ;
918
+ const args = parseUnparsed ( declaration . value . value , builder , property ) ;
919
919
920
920
if ( property === "animation" ) {
921
921
builder . addDescriptor ( "animation" , [
@@ -932,7 +932,7 @@ export function parseUnparsedDeclaration(
932
932
] ) ;
933
933
}
934
934
} else {
935
- const value = parseUnparsed ( declaration . value . value , builder ) ;
935
+ const value = parseUnparsed ( declaration . value . value , builder , property ) ;
936
936
937
937
builder . addDescriptor ( property , value ) ;
938
938
@@ -958,13 +958,13 @@ export function parseCustomDeclaration(
958
958
) {
959
959
builder . addDescriptor (
960
960
property ,
961
- parseUnparsed ( declaration . value . value , builder , allowAuto . has ( property ) ) ,
961
+ parseUnparsed ( declaration . value . value , builder , property ) ,
962
962
) ;
963
963
} else if ( property === "-webkit-line-clamp" ) {
964
964
builder . addMapping ( { [ property ] : [ "numberOfLines" ] } ) ;
965
965
builder . addDescriptor (
966
966
property ,
967
- parseUnparsed ( declaration . value . value , builder , allowAuto . has ( property ) ) ,
967
+ parseUnparsed ( declaration . value . value , builder , property ) ,
968
968
) ;
969
969
} else {
970
970
builder . addWarning ( "property" , declaration . value . name ) ;
@@ -974,10 +974,13 @@ export function parseCustomDeclaration(
974
974
export function reduceParseUnparsed (
975
975
tokenOrValues : TokenOrValue [ ] ,
976
976
builder : StylesheetBuilder ,
977
+ property : string ,
977
978
allowAuto : boolean ,
978
979
) : StyleDescriptor {
979
980
const result = tokenOrValues
980
- . map ( ( tokenOrValue ) => parseUnparsed ( tokenOrValue , builder , allowAuto ) )
981
+ . map ( ( tokenOrValue ) =>
982
+ parseUnparsed ( tokenOrValue , builder , property , allowAuto ) ,
983
+ )
981
984
. filter ( ( v ) => v !== undefined ) ;
982
985
983
986
if ( result . length === 0 ) {
@@ -996,6 +999,8 @@ export function reduceParseUnparsed(
996
999
}
997
1000
}
998
1001
1002
+ // Groups are the tokens grouped together by comma location
1003
+ // If a group only has 1 item, it shouldn't be an array
999
1004
groups = groups . flatMap ( ( group ) : StyleDescriptor [ ] => {
1000
1005
if ( ! Array . isArray ( group ) ) {
1001
1006
return [ ] ;
@@ -1011,6 +1016,17 @@ export function reduceParseUnparsed(
1011
1016
} else {
1012
1017
return [ first ] ;
1013
1018
}
1019
+ } else if (
1020
+ // This is a special case for <ratio> values
1021
+ group . includes ( "/" ) &&
1022
+ group . every ( ( item ) =>
1023
+ typeof item === "string" && item === "/"
1024
+ ? item
1025
+ : typeof item === "number" ,
1026
+ )
1027
+ ) {
1028
+ // eslint-disable-next-line @typescript-eslint/no-base-to-string
1029
+ return [ group . join ( " " ) ] ;
1014
1030
} else {
1015
1031
return [ group ] ;
1016
1032
}
@@ -1022,12 +1038,13 @@ export function reduceParseUnparsed(
1022
1038
export function unparsedFunction (
1023
1039
token : Extract < TokenOrValue , { type : "function" } > ,
1024
1040
builder : StylesheetBuilder ,
1041
+ property : string ,
1025
1042
allowAuto : boolean ,
1026
1043
) : StyleFunction {
1027
1044
return [
1028
1045
{ } ,
1029
1046
token . value . name ,
1030
- reduceParseUnparsed ( token . value . arguments , builder , allowAuto ) ,
1047
+ reduceParseUnparsed ( token . value . arguments , builder , property , allowAuto ) ,
1031
1048
] ;
1032
1049
}
1033
1050
@@ -1044,7 +1061,8 @@ export function parseUnparsed(
1044
1061
| undefined
1045
1062
| null ,
1046
1063
builder : StylesheetBuilder ,
1047
- allowAuto = false ,
1064
+ property : string ,
1065
+ allowAuto = allowAutoProperties . has ( property ) ,
1048
1066
) : StyleDescriptor {
1049
1067
if ( tokenOrValue === undefined || tokenOrValue === null ) {
1050
1068
return ;
@@ -1067,21 +1085,32 @@ export function parseUnparsed(
1067
1085
}
1068
1086
1069
1087
if ( Array . isArray ( tokenOrValue ) ) {
1070
- const args = reduceParseUnparsed ( tokenOrValue , builder , allowAuto ) ;
1088
+ const args = reduceParseUnparsed (
1089
+ tokenOrValue ,
1090
+ builder ,
1091
+ property ,
1092
+ allowAuto ,
1093
+ ) ;
1071
1094
if ( ! args ) return ;
1072
1095
if ( Array . isArray ( args ) && args . length === 1 ) return args [ 0 ] ;
1073
1096
return args ;
1074
1097
}
1075
1098
1076
1099
switch ( tokenOrValue . type ) {
1077
1100
case "unresolved-color" : {
1078
- return parseUnresolvedColor ( tokenOrValue . value , builder , allowAuto ) ;
1101
+ return parseUnresolvedColor (
1102
+ tokenOrValue . value ,
1103
+ builder ,
1104
+ property ,
1105
+ allowAuto ,
1106
+ ) ;
1079
1107
}
1080
1108
case "var" : {
1081
1109
let args : StyleDescriptor = tokenOrValue . value . name . ident . slice ( 2 ) ;
1082
1110
const fallback = parseUnparsed (
1083
1111
tokenOrValue . value . fallback ,
1084
1112
builder ,
1113
+ property ,
1085
1114
allowAuto ,
1086
1115
) ;
1087
1116
if ( fallback !== undefined ) {
@@ -1104,7 +1133,7 @@ export function parseUnparsed(
1104
1133
case "translateX" :
1105
1134
case "translateY" :
1106
1135
tokenOrValue . value . name = `@${ tokenOrValue . value . name } ` ;
1107
- return unparsedFunction ( tokenOrValue , builder , allowAuto ) ;
1136
+ return unparsedFunction ( tokenOrValue , builder , property , allowAuto ) ;
1108
1137
case "blur" :
1109
1138
case "brightness" :
1110
1139
case "contrast" :
@@ -1129,7 +1158,7 @@ export function parseUnparsed(
1129
1158
case "sepia" :
1130
1159
case "shadow" :
1131
1160
case "steps" :
1132
- return unparsedFunction ( tokenOrValue , builder , allowAuto ) ;
1161
+ return unparsedFunction ( tokenOrValue , builder , property , allowAuto ) ;
1133
1162
case "hairlineWidth" :
1134
1163
return [ { } , tokenOrValue . value . name , [ ] ] ;
1135
1164
case "calc" :
@@ -1140,6 +1169,7 @@ export function parseUnparsed(
1140
1169
tokenOrValue . value . name ,
1141
1170
tokenOrValue . value . arguments ,
1142
1171
builder ,
1172
+ property ,
1143
1173
) ;
1144
1174
default : {
1145
1175
builder . addWarning ( "value" , `${ tokenOrValue . value . name } ()` ) ;
@@ -1188,11 +1218,16 @@ export function parseUnparsed(
1188
1218
return parseDimension ( tokenOrValue . value , builder ) ;
1189
1219
case "comma" :
1190
1220
return CommaSeparator as unknown as StyleDescriptor ;
1221
+ case "delim" : {
1222
+ if ( property === "aspect-ratio" && tokenOrValue . value . value === "/" ) {
1223
+ return tokenOrValue . value . value ;
1224
+ }
1225
+ return ;
1226
+ }
1191
1227
case "at-keyword" :
1192
1228
case "hash" :
1193
1229
case "id-hash" :
1194
1230
case "unquoted-url" :
1195
- case "delim" :
1196
1231
case "white-space" :
1197
1232
case "comment" :
1198
1233
case "colon" :
@@ -2440,7 +2475,7 @@ export function parseDimensionPercentageFor_LengthValue(
2440
2475
}
2441
2476
}
2442
2477
2443
- const allowAuto = new Set ( [ "pointer-events" ] ) ;
2478
+ const allowAutoProperties = new Set ( [ "pointer-events" ] ) ;
2444
2479
2445
2480
export function parseEnv (
2446
2481
value : EnvironmentVariable ,
@@ -2458,7 +2493,7 @@ export function parseEnv(
2458
2493
"var" ,
2459
2494
[
2460
2495
`--react-native-css-${ value . name . value } ` ,
2461
- parseUnparsed ( value . fallback , builder ) ,
2496
+ parseUnparsed ( value . fallback , builder , value . name . value ) ,
2462
2497
] ,
2463
2498
1 ,
2464
2499
] ;
@@ -2481,8 +2516,9 @@ export function parseCalcFn(
2481
2516
name : string ,
2482
2517
tokens : TokenOrValue [ ] ,
2483
2518
builder : StylesheetBuilder ,
2519
+ property : string ,
2484
2520
) : StyleDescriptor {
2485
- const args = parseCalcArguments ( tokens , builder ) ;
2521
+ const args = parseCalcArguments ( tokens , builder , property ) ;
2486
2522
if ( args ) {
2487
2523
return [ { } , name , args ] ;
2488
2524
}
@@ -2493,6 +2529,7 @@ export function parseCalcFn(
2493
2529
export function parseCalcArguments (
2494
2530
[ ...args ] : TokenOrValue [ ] ,
2495
2531
builder : StylesheetBuilder ,
2532
+ property : string ,
2496
2533
) {
2497
2534
const parsed : StyleDescriptor [ ] = [ ] ;
2498
2535
@@ -2507,7 +2544,7 @@ export function parseCalcArguments(
2507
2544
case "var" :
2508
2545
case "function" :
2509
2546
case "unresolved-color" : {
2510
- const value = parseUnparsed ( arg , builder ) ;
2547
+ const value = parseUnparsed ( arg , builder , property ) ;
2511
2548
2512
2549
if ( value === undefined ) {
2513
2550
return undefined ;
@@ -2583,7 +2620,7 @@ export function parseCalcArguments(
2583
2620
// Then drop the surrounding parenthesis
2584
2621
. slice ( 1 , - 1 ) ;
2585
2622
2586
- parsed . push ( parseCalcFn ( "calc" , innerCalcArgs , builder ) ) ;
2623
+ parsed . push ( parseCalcFn ( "calc" , innerCalcArgs , builder , property ) ) ;
2587
2624
2588
2625
break ;
2589
2626
}
@@ -2636,6 +2673,7 @@ export function parseTranslateProp(
2636
2673
export function parseUnresolvedColor (
2637
2674
color : UnresolvedColor ,
2638
2675
builder : StylesheetBuilder ,
2676
+ property : string ,
2639
2677
allowAuto : boolean ,
2640
2678
) : StyleDescriptor {
2641
2679
switch ( color . type ) {
@@ -2647,26 +2685,31 @@ export function parseUnresolvedColor(
2647
2685
round ( color . r * 255 ) ,
2648
2686
round ( color . g * 255 ) ,
2649
2687
round ( color . b * 255 ) ,
2650
- parseUnparsed ( color . alpha , builder ) ,
2688
+ parseUnparsed ( color . alpha , builder , property ) ,
2651
2689
] ,
2652
2690
] ;
2653
2691
case "hsl" :
2654
2692
return [
2655
2693
{ } ,
2656
2694
color . type ,
2657
- [ color . h , color . s , color . l , parseUnparsed ( color . alpha , builder ) ] ,
2695
+ [
2696
+ color . h ,
2697
+ color . s ,
2698
+ color . l ,
2699
+ parseUnparsed ( color . alpha , builder , property ) ,
2700
+ ] ,
2658
2701
] ;
2659
2702
case "light-dark" : {
2660
2703
const extraRule = builder . extendRule ( {
2661
2704
m : [ [ "=" , "prefers-color-scheme" , "dark" ] ] ,
2662
2705
} ) ;
2663
2706
builder . addUnnamedDescriptor (
2664
- reduceParseUnparsed ( color . dark , builder , allowAuto ) ,
2707
+ reduceParseUnparsed ( color . dark , builder , property , allowAuto ) ,
2665
2708
false ,
2666
2709
extraRule ,
2667
2710
) ;
2668
2711
builder . addExtraRule ( extraRule ) ;
2669
- return reduceParseUnparsed ( color . light , builder , allowAuto ) ;
2712
+ return reduceParseUnparsed ( color . light , builder , property , allowAuto ) ;
2670
2713
}
2671
2714
default :
2672
2715
color satisfies never ;
0 commit comments