Skip to content

Commit

Permalink
fix(issue:4301) at-rule declarations missing
Browse files Browse the repository at this point in the history
* Fixes issue less#4301. At-rule declarations may go missing or are
  incorrectly merged under certain nesting conditions.
* Added more ```@container``` tests.
  • Loading branch information
puckowski committed Dec 19, 2024
1 parent 145d95e commit 8677acb
Show file tree
Hide file tree
Showing 3 changed files with 176 additions and 0 deletions.
6 changes: 6 additions & 0 deletions packages/less/src/less/tree/nested-at-rule.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,12 @@ const NestableAtRulePrototype = {

// Extract the media-query conditions separated with `,` (OR).
for (i = 0; i < path.length; i++) {
if (path[i].type !== this.type) {
context.mediaBlocks.splice(i, 1);

return this;
}

value = path[i].features instanceof Value ?
path[i].features.value : path[i].features;
path[i] = Array.isArray(value) ? value : [value];
Expand Down
76 changes: 76 additions & 0 deletions packages/test-data/css/_main/container.css
Original file line number Diff line number Diff line change
Expand Up @@ -165,3 +165,79 @@
max-height: 300;
}
}
@media only screen and (min-width: 768px) {
@container (min-width: 500px) {
.primary-content {
font-size: 1rem;
}
}
}
@media only screen and (min-width: 768px) {
.media-1 {
font-size: 1.5rem;
}
@container (min-width: 500px) {
.primary-content {
font-size: 1rem;
}
}
}
@media only screen and (min-width: 768px) {
.media-1 {
font-size: 1.5rem;
}
@container (min-width: 500px) {
.primary-content {
font-size: 1rem;
}
}
.media-2 {
font-size: 2rem;
}
}
@media only screen and (min-width: 768px) {
.media-1 {
font-size: 1.5rem;
}
@container (min-width: 500px) {
.primary-content {
font-size: 1rem;
}
@media (hover: hover) {
font-size: 1.75rem;
}
}
.media-2 {
font-size: 2rem;
}
}
@media only screen and (min-width: 768px) {
.media-1 {
font-size: 1.5rem;
}
@container (min-width: 500px) {
.primary-content {
font-size: 1rem;
}
@media (hover: hover) {
font-size: 1.75rem;
@media not all and (hover: hover) {
color: limegreen;
}
.media-3 {
padding: 0.5rem;
}
}
}
.media-2 {
font-size: 2rem;
}
}
@container (min-width: 768px) {
@media only screen and (min-width: 768px) {
color: aliceblue;
}
.container-1 {
color: purple;
}
}
94 changes: 94 additions & 0 deletions packages/test-data/less/_main/container.less
Original file line number Diff line number Diff line change
Expand Up @@ -195,3 +195,97 @@
.my_mixin(100);
.my_mixin(200);
.my_mixin(300);

@media only screen and (min-width: 768px) {
@container (min-width: 500px) {
.primary-content {
font-size: 1rem;
}
}
}

@media only screen and (min-width: 768px) {
.media-1 {
font-size: 1.5rem;
}

@container (min-width: 500px) {
.primary-content {
font-size: 1rem;
}
}
}

@media only screen and (min-width: 768px) {
.media-1 {
font-size: 1.5rem;
}

@container (min-width: 500px) {
.primary-content {
font-size: 1rem;
}
}

.media-2 {
font-size: 2rem;
}
}

@media only screen and (min-width: 768px) {
.media-1 {
font-size: 1.5rem;
}

@container (min-width: 500px) {
.primary-content {
font-size: 1rem;
}

@media (hover: hover) {
font-size: 1.75rem;
}
}

.media-2 {
font-size: 2rem;
}
}

@media only screen and (min-width: 768px) {
.media-1 {
font-size: 1.5rem;
}

@container (min-width: 500px) {
.primary-content {
font-size: 1rem;
}

@media (hover: hover) {
font-size: 1.75rem;

@media not all and (hover: hover) {
color: limegreen;
}

.media-3 {
padding: 0.5rem;
}
}
}

.media-2 {
font-size: 2rem;
}
}

@container (min-width: 768px) {
@media only screen and (min-width: 768px) {
color: aliceblue;
}

.container-1 {
color: purple;
}
}

0 comments on commit 8677acb

Please sign in to comment.