Skip to content

Commit 9d92b0c

Browse files
authored
fix(issue:4301) at-rule declarations missing (less#4302)
* Fixes issue less#4301. At-rule declarations may go missing or are incorrectly merged under certain nesting conditions. * Added more ```@container``` tests.
1 parent 145d95e commit 9d92b0c

File tree

3 files changed

+176
-0
lines changed

3 files changed

+176
-0
lines changed

packages/less/src/less/tree/nested-at-rule.js

+6
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,12 @@ const NestableAtRulePrototype = {
4545

4646
// Extract the media-query conditions separated with `,` (OR).
4747
for (i = 0; i < path.length; i++) {
48+
if (path[i].type !== this.type) {
49+
context.mediaBlocks.splice(i, 1);
50+
51+
return this;
52+
}
53+
4854
value = path[i].features instanceof Value ?
4955
path[i].features.value : path[i].features;
5056
path[i] = Array.isArray(value) ? value : [value];

packages/test-data/css/_main/container.css

+76
Original file line numberDiff line numberDiff line change
@@ -165,3 +165,79 @@
165165
max-height: 300;
166166
}
167167
}
168+
@media only screen and (min-width: 768px) {
169+
@container (min-width: 500px) {
170+
.primary-content {
171+
font-size: 1rem;
172+
}
173+
}
174+
}
175+
@media only screen and (min-width: 768px) {
176+
.media-1 {
177+
font-size: 1.5rem;
178+
}
179+
@container (min-width: 500px) {
180+
.primary-content {
181+
font-size: 1rem;
182+
}
183+
}
184+
}
185+
@media only screen and (min-width: 768px) {
186+
.media-1 {
187+
font-size: 1.5rem;
188+
}
189+
@container (min-width: 500px) {
190+
.primary-content {
191+
font-size: 1rem;
192+
}
193+
}
194+
.media-2 {
195+
font-size: 2rem;
196+
}
197+
}
198+
@media only screen and (min-width: 768px) {
199+
.media-1 {
200+
font-size: 1.5rem;
201+
}
202+
@container (min-width: 500px) {
203+
.primary-content {
204+
font-size: 1rem;
205+
}
206+
@media (hover: hover) {
207+
font-size: 1.75rem;
208+
}
209+
}
210+
.media-2 {
211+
font-size: 2rem;
212+
}
213+
}
214+
@media only screen and (min-width: 768px) {
215+
.media-1 {
216+
font-size: 1.5rem;
217+
}
218+
@container (min-width: 500px) {
219+
.primary-content {
220+
font-size: 1rem;
221+
}
222+
@media (hover: hover) {
223+
font-size: 1.75rem;
224+
@media not all and (hover: hover) {
225+
color: limegreen;
226+
}
227+
.media-3 {
228+
padding: 0.5rem;
229+
}
230+
}
231+
}
232+
.media-2 {
233+
font-size: 2rem;
234+
}
235+
}
236+
@container (min-width: 768px) {
237+
@media only screen and (min-width: 768px) {
238+
color: aliceblue;
239+
}
240+
.container-1 {
241+
color: purple;
242+
}
243+
}

packages/test-data/less/_main/container.less

+94
Original file line numberDiff line numberDiff line change
@@ -195,3 +195,97 @@
195195
.my_mixin(100);
196196
.my_mixin(200);
197197
.my_mixin(300);
198+
199+
@media only screen and (min-width: 768px) {
200+
@container (min-width: 500px) {
201+
.primary-content {
202+
font-size: 1rem;
203+
}
204+
}
205+
}
206+
207+
@media only screen and (min-width: 768px) {
208+
.media-1 {
209+
font-size: 1.5rem;
210+
}
211+
212+
@container (min-width: 500px) {
213+
.primary-content {
214+
font-size: 1rem;
215+
}
216+
}
217+
}
218+
219+
@media only screen and (min-width: 768px) {
220+
.media-1 {
221+
font-size: 1.5rem;
222+
}
223+
224+
@container (min-width: 500px) {
225+
.primary-content {
226+
font-size: 1rem;
227+
}
228+
}
229+
230+
.media-2 {
231+
font-size: 2rem;
232+
}
233+
}
234+
235+
@media only screen and (min-width: 768px) {
236+
.media-1 {
237+
font-size: 1.5rem;
238+
}
239+
240+
@container (min-width: 500px) {
241+
.primary-content {
242+
font-size: 1rem;
243+
}
244+
245+
@media (hover: hover) {
246+
font-size: 1.75rem;
247+
}
248+
}
249+
250+
.media-2 {
251+
font-size: 2rem;
252+
}
253+
}
254+
255+
@media only screen and (min-width: 768px) {
256+
.media-1 {
257+
font-size: 1.5rem;
258+
}
259+
260+
@container (min-width: 500px) {
261+
.primary-content {
262+
font-size: 1rem;
263+
}
264+
265+
@media (hover: hover) {
266+
font-size: 1.75rem;
267+
268+
@media not all and (hover: hover) {
269+
color: limegreen;
270+
}
271+
272+
.media-3 {
273+
padding: 0.5rem;
274+
}
275+
}
276+
}
277+
278+
.media-2 {
279+
font-size: 2rem;
280+
}
281+
}
282+
283+
@container (min-width: 768px) {
284+
@media only screen and (min-width: 768px) {
285+
color: aliceblue;
286+
}
287+
288+
.container-1 {
289+
color: purple;
290+
}
291+
}

0 commit comments

Comments
 (0)