@@ -11,6 +11,7 @@ import {
1111 type Visitor ,
1212} from "lightningcss" ;
1313
14+ import { maybeMutateReactNativeOptions , parsePropAtRule } from "./atRules" ;
1415import type {
1516 CompilerOptions ,
1617 ContainerQuery ,
@@ -20,7 +21,7 @@ import { parseContainerCondition } from "./container-query";
2021import { parseDeclaration } from "./declarations" ;
2122import { extractKeyFrames } from "./keyframes" ;
2223import { parseMediaQuery } from "./media-query" ;
23- import { maybeMutateReactNativeOptions , parsePropAtRule } from "./atRules " ;
24+ import { getSelectors } from "./selectors " ;
2425import { StylesheetBuilder } from "./stylesheet" ;
2526
2627/**
@@ -37,6 +38,10 @@ export function compile(
3738 const { logger = debug ( "react-native-css" ) } = options ;
3839 const features = Object . assign ( { } , options . features ) ;
3940
41+ if ( options . selectorPrefix && options . selectorPrefix . startsWith ( "." ) ) {
42+ options . selectorPrefix = options . selectorPrefix . slice ( 1 ) ;
43+ }
44+
4045 logger ( `Features ${ JSON . stringify ( features ) } ` ) ;
4146
4247 const builder = new StylesheetBuilder ( options ) ;
@@ -131,24 +136,31 @@ function extractRule(rule: Rule, builder: StylesheetBuilder) {
131136 case "style" : {
132137 // If the rule is a style declaration, extract it with the `getExtractedStyle` function and store it in the `declarations` map
133138 builder = builder . fork ( "style" ) ;
134- builder . newRule ( parsePropAtRule ( rule . value . rules ) ) ;
135139
136140 const declarationBlock = rule . value . declarations ;
141+ const mapping = parsePropAtRule ( rule . value . rules ) ;
142+ const selectors = getSelectors (
143+ rule . value . selectors ,
144+ false ,
145+ builder . getOptions ( ) ,
146+ ) ;
137147
138148 if ( declarationBlock ) {
139149 if ( declarationBlock . declarations ) {
150+ builder . newRule ( mapping ) ;
140151 for ( const declaration of declarationBlock . declarations ) {
141152 parseDeclaration ( declaration , builder ) ;
142153 }
154+ builder . applyRuleToSelectors ( selectors ) ;
143155 }
144156
145157 if ( declarationBlock . importantDeclarations ) {
158+ builder . newRule ( mapping , { important : true } ) ;
146159 for ( const declaration of declarationBlock . importantDeclarations ) {
147160 parseDeclaration ( declaration , builder ) ;
148161 }
162+ builder . applyRuleToSelectors ( selectors ) ;
149163 }
150-
151- builder . applyRuleToSelectors ( rule . value . selectors ) ;
152164 }
153165 break ;
154166 }
0 commit comments