Skip to content

Commit e4fdbe3

Browse files
authored
Master fix 4252 (#4295)
* fix(issue:4252) container query mixin reference * Fixes a container query mixin reference issue and adds container query test. * refactor: clean up fix for issue 4252 * Refactor and clean up fix for issue #4252.
1 parent e4198ba commit e4fdbe3

File tree

3 files changed

+74
-1
lines changed

3 files changed

+74
-1
lines changed

packages/less/src/less/tree/query-in-parens.js

+38-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import { copy } from 'copy-anything';
2+
import Declaration from './declaration';
13
import Node from './node';
24

35
const QueryInParens = function (op, l, m, op2, r, i) {
@@ -7,6 +9,7 @@ const QueryInParens = function (op, l, m, op2, r, i) {
79
this.op2 = op2 ? op2.trim() : null;
810
this.rvalue = r;
911
this._index = i;
12+
this.mvalues = [];
1013
};
1114

1215
QueryInParens.prototype = Object.assign(new Node(), {
@@ -22,7 +25,38 @@ QueryInParens.prototype = Object.assign(new Node(), {
2225

2326
eval(context) {
2427
this.lvalue = this.lvalue.eval(context);
25-
this.mvalue = this.mvalue.eval(context);
28+
29+
let variableDeclaration;
30+
let rule;
31+
32+
for (let i = 0; (rule = context.frames[i]); i++) {
33+
if (rule.type === 'Ruleset') {
34+
variableDeclaration = rule.rules.find(function (r) {
35+
if ((r instanceof Declaration) && r.variable) {
36+
return true;
37+
}
38+
39+
return false;
40+
});
41+
42+
if (variableDeclaration) {
43+
break;
44+
}
45+
}
46+
}
47+
48+
if (!this.mvalueCopy) {
49+
this.mvalueCopy = copy(this.mvalue);
50+
}
51+
52+
if (variableDeclaration) {
53+
this.mvalue = this.mvalueCopy;
54+
this.mvalue = this.mvalue.eval(context);
55+
this.mvalues.push(this.mvalue);
56+
} else {
57+
this.mvalue = this.mvalue.eval(context);
58+
}
59+
2660
if (this.rvalue) {
2761
this.rvalue = this.rvalue.eval(context);
2862
}
@@ -32,6 +66,9 @@ QueryInParens.prototype = Object.assign(new Node(), {
3266
genCSS(context, output) {
3367
this.lvalue.genCSS(context, output);
3468
output.add(' ' + this.op + ' ');
69+
if (this.mvalues.length > 0) {
70+
this.mvalue = this.mvalues.shift();
71+
}
3572
this.mvalue.genCSS(context, output);
3673
if (this.rvalue) {
3774
output.add(' ' + this.op2 + ' ');

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

+19
Original file line numberDiff line numberDiff line change
@@ -146,3 +146,22 @@
146146
margin: 0.5em 0 0 0;
147147
}
148148
}
149+
.wrapper {
150+
container-name: wrapper;
151+
container-type: size;
152+
}
153+
@container wrapper (height < 100) {
154+
a {
155+
max-height: 100;
156+
}
157+
}
158+
@container wrapper (height < 200) {
159+
a {
160+
max-height: 200;
161+
}
162+
}
163+
@container wrapper (height < 300) {
164+
a {
165+
max-height: 300;
166+
}
167+
}

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

+17
Original file line numberDiff line numberDiff line change
@@ -178,3 +178,20 @@
178178
}
179179
}
180180
}
181+
182+
.wrapper {
183+
container-name: wrapper;
184+
container-type: size;
185+
}
186+
187+
.my_mixin(@height) {
188+
@container wrapper (height < @height) {
189+
a {
190+
max-height: @height;
191+
}
192+
}
193+
}
194+
195+
.my_mixin(100);
196+
.my_mixin(200);
197+
.my_mixin(300);

0 commit comments

Comments
 (0)