@@ -79,6 +79,123 @@ describe('combining multiple classes', () => {
7979 } ) ;
8080} ) ;
8181
82+ describe ( 'Classname is part of a selector' , ( ) => {
83+
84+ test ( 'CSS Modules class targetting children' , async ( ) => {
85+ const source =
86+ '<style>\n' +
87+ 'div.red > sup { font-size: 12px; }\n' +
88+ '.red { color: red; }\n' +
89+ '</style>\n' +
90+ '<div class="$style.red">Red<sup>*</sup></div>' ;
91+
92+ const expectedOutput =
93+ '<style>\n' +
94+ ':global(div.red-123) > sup { font-size: 12px; }\n' +
95+ ':global(.red-123) { color: red; }\n' +
96+ '</style>\n' +
97+ '<div class="red-123">Red<sup>*</sup></div>' ;
98+
99+ const output = await compiler (
100+ {
101+ source,
102+ } ,
103+ {
104+ localIdentName : '[local]-123' ,
105+ }
106+ ) ;
107+
108+ expect ( output ) . toBe ( expectedOutput ) ;
109+ } ) ;
110+
111+ test ( 'CSS Modules class has a parent' , async ( ) => {
112+ const source =
113+ '<style>\n' +
114+ 'div .semibold .red { font-size: 20px; }\n' +
115+ '.red { color: red; }\n' +
116+ '.semibold { font-weight: 600; }\n' +
117+ '</style>\n' +
118+ '<div><strong class="$style.semibold"><span class="$style.red">Red</span></strong></div>' ;
119+
120+ const expectedOutput =
121+ '<style>\n' +
122+ 'div :global(.semibold-123) :global(.red-123) { font-size: 20px; }\n' +
123+ ':global(.red-123) { color: red; }\n' +
124+ ':global(.semibold-123) { font-weight: 600; }\n' +
125+ '</style>\n' +
126+ '<div><strong class="semibold-123"><span class="red-123">Red</span></strong></div>' ;
127+
128+ const output = await compiler (
129+ {
130+ source,
131+ } ,
132+ {
133+ localIdentName : '[local]-123' ,
134+ }
135+ ) ;
136+
137+ expect ( output ) . toBe ( expectedOutput ) ;
138+ } ) ;
139+
140+ test ( 'CSS Modules class has a global parent' , async ( ) => {
141+ const source =
142+ '<style>\n' +
143+ ':global(div) .red { font-size: 20px; }\n' +
144+ '.red { color: red; }\n' +
145+ '</style>\n' +
146+ '<div><span class="$style.red">Red</span></div>' ;
147+
148+ const expectedOutput =
149+ '<style>\n' +
150+ ':global(div) :global(.red-123) { font-size: 20px; }\n' +
151+ ':global(.red-123) { color: red; }\n' +
152+ '</style>\n' +
153+ '<div><span class="red-123">Red</span></div>' ;
154+
155+ const output = await compiler (
156+ {
157+ source,
158+ } ,
159+ {
160+ localIdentName : '[local]-123' ,
161+ }
162+ ) ;
163+
164+ expect ( output ) . toBe ( expectedOutput ) ;
165+ } ) ;
166+
167+ test ( 'CSS Modules class is used within a media query' , async ( ) => {
168+ const source =
169+ '<style>\n' +
170+ '@media (min-width: 37.5em) {\n' +
171+ '.red { color: red; }\n' +
172+ 'div.bold { font-weight: bold; }\n' +
173+ '}\n' +
174+ '</style>\n' +
175+ '<div class="$style.bold"><span class="$style.red">Red</span></div>' ;
176+
177+ const expectedOutput =
178+ '<style>\n' +
179+ '@media (min-width: 37.5em) {\n' +
180+ ':global(.red-123) { color: red; }\n' +
181+ ':global(div.bold-123) { font-weight: bold; }\n' +
182+ '}\n' +
183+ '</style>\n' +
184+ '<div class="bold-123"><span class="red-123">Red</span></div>' ;
185+
186+ const output = await compiler (
187+ {
188+ source,
189+ } ,
190+ {
191+ localIdentName : '[local]-123' ,
192+ }
193+ ) ;
194+
195+ expect ( output ) . toBe ( expectedOutput ) ;
196+ } ) ;
197+ } ) ;
198+
82199describe ( 'using dynamic classes' , ( ) => {
83200 describe ( 'when matched class is empty' , ( ) => {
84201 // The parser will identify a class named ''
0 commit comments