Skip to content

Commit 53f84f0

Browse files
authored
Master container style fix for 4235 (#4237)
* fix(issue:4211) parse entities for comma list parse the correct entities for a comma separated list so that all URLs are rewritten correctly. * fix(issue #4235) style must not have space fixes issue #4235 where container query style would have invalid space after keyword
1 parent 13864a6 commit 53f84f0

File tree

11 files changed

+196
-13
lines changed

11 files changed

+196
-13
lines changed

dist/less.js

+59-2
Original file line numberDiff line numberDiff line change
@@ -3622,6 +3622,32 @@
36223622
parserInput.forget();
36233623
return new (tree.Call)(name, args, index + currentIndex, fileInfo);
36243624
},
3625+
declarationCall: function () {
3626+
var validCall;
3627+
var args;
3628+
var index = parserInput.i;
3629+
parserInput.save();
3630+
validCall = parserInput.$re(/^[\w]+\(/);
3631+
if (!validCall) {
3632+
parserInput.forget();
3633+
return;
3634+
}
3635+
validCall = validCall.substring(0, validCall.length - 1);
3636+
var rule = this.ruleProperty();
3637+
var value;
3638+
if (rule) {
3639+
value = this.value();
3640+
}
3641+
if (rule && value) {
3642+
args = [new (tree.Declaration)(rule, value, null, null, parserInput.i + currentIndex, fileInfo, true)];
3643+
}
3644+
if (!parserInput.$char(')')) {
3645+
parserInput.restore('Could not parse call arguments or missing \')\'');
3646+
return;
3647+
}
3648+
parserInput.forget();
3649+
return new (tree.Call)(validCall, args, index + currentIndex, fileInfo);
3650+
},
36253651
//
36263652
// Parsing rules for functions with non-standard args, e.g.:
36273653
//
@@ -4706,6 +4732,10 @@
47064732
if (e) {
47074733
value.push(e);
47084734
}
4735+
if (parserInput.peek(',')) {
4736+
value.push(new (tree.Anonymous)(',', parserInput.i));
4737+
parserInput.$char(',');
4738+
}
47094739
} while (e);
47104740
done = testCurrentChar();
47114741
if (value.length > 0) {
@@ -4833,7 +4863,7 @@
48334863
var rangeP;
48344864
parserInput.save();
48354865
do {
4836-
e = entities.keyword() || entities.variable() || entities.mixinLookup();
4866+
e = entities.declarationCall.bind(this)() || entities.keyword() || entities.variable() || entities.mixinLookup();
48374867
if (e) {
48384868
nodes.push(e);
48394869
}
@@ -7125,7 +7155,10 @@
71257155
for (var i_1 = 0; i_1 < this.value.length; i_1++) {
71267156
this.value[i_1].genCSS(context, output);
71277157
if (!this.noSpacing && i_1 + 1 < this.value.length) {
7128-
output.add(' ');
7158+
if (i_1 + 1 < this.value.length && !(this.value[i_1 + 1] instanceof Anonymous) ||
7159+
this.value[i_1 + 1] instanceof Anonymous && this.value[i_1 + 1].value !== ',') {
7160+
output.add(' ');
7161+
}
71297162
}
71307163
}
71317164
},
@@ -9945,6 +9978,29 @@
99459978
}
99469979
};
99479980

9981+
var styleExpression = function (args) {
9982+
var _this = this;
9983+
args = Array.prototype.slice.call(args);
9984+
switch (args.length) {
9985+
case 0: throw { type: 'Argument', message: 'one or more arguments required' };
9986+
}
9987+
var entityList = [new Variable(args[0].value, this.index, this.currentFileInfo).eval(this.context)];
9988+
args = entityList.map(function (a) { return a.toCSS(_this.context); }).join(this.context.compress ? ',' : ', ');
9989+
return new Variable("style(" + args + ")");
9990+
};
9991+
var style$1 = {
9992+
style: function () {
9993+
var args = [];
9994+
for (var _i = 0; _i < arguments.length; _i++) {
9995+
args[_i] = arguments[_i];
9996+
}
9997+
try {
9998+
return styleExpression.call(this, args);
9999+
}
10000+
catch (e) { }
10001+
},
10002+
};
10003+
994810004
var functions = (function (environment) {
994910005
var functions = { functionRegistry: functionRegistry, functionCaller: functionCaller };
995010006
// register functions
@@ -9959,6 +10015,7 @@
995910015
functionRegistry.addMultiple(string);
996010016
functionRegistry.addMultiple(svg());
996110017
functionRegistry.addMultiple(types);
10018+
functionRegistry.addMultiple(style$1);
996210019
return functions;
996310020
});
996410021

dist/less.min.js

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/less.min.js.map

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/less/dist/less.js

+59-2
Original file line numberDiff line numberDiff line change
@@ -3622,6 +3622,32 @@
36223622
parserInput.forget();
36233623
return new (tree.Call)(name, args, index + currentIndex, fileInfo);
36243624
},
3625+
declarationCall: function () {
3626+
var validCall;
3627+
var args;
3628+
var index = parserInput.i;
3629+
parserInput.save();
3630+
validCall = parserInput.$re(/^[\w]+\(/);
3631+
if (!validCall) {
3632+
parserInput.forget();
3633+
return;
3634+
}
3635+
validCall = validCall.substring(0, validCall.length - 1);
3636+
var rule = this.ruleProperty();
3637+
var value;
3638+
if (rule) {
3639+
value = this.value();
3640+
}
3641+
if (rule && value) {
3642+
args = [new (tree.Declaration)(rule, value, null, null, parserInput.i + currentIndex, fileInfo, true)];
3643+
}
3644+
if (!parserInput.$char(')')) {
3645+
parserInput.restore('Could not parse call arguments or missing \')\'');
3646+
return;
3647+
}
3648+
parserInput.forget();
3649+
return new (tree.Call)(validCall, args, index + currentIndex, fileInfo);
3650+
},
36253651
//
36263652
// Parsing rules for functions with non-standard args, e.g.:
36273653
//
@@ -4706,6 +4732,10 @@
47064732
if (e) {
47074733
value.push(e);
47084734
}
4735+
if (parserInput.peek(',')) {
4736+
value.push(new (tree.Anonymous)(',', parserInput.i));
4737+
parserInput.$char(',');
4738+
}
47094739
} while (e);
47104740
done = testCurrentChar();
47114741
if (value.length > 0) {
@@ -4833,7 +4863,7 @@
48334863
var rangeP;
48344864
parserInput.save();
48354865
do {
4836-
e = entities.keyword() || entities.variable() || entities.mixinLookup();
4866+
e = entities.declarationCall.bind(this)() || entities.keyword() || entities.variable() || entities.mixinLookup();
48374867
if (e) {
48384868
nodes.push(e);
48394869
}
@@ -7125,7 +7155,10 @@
71257155
for (var i_1 = 0; i_1 < this.value.length; i_1++) {
71267156
this.value[i_1].genCSS(context, output);
71277157
if (!this.noSpacing && i_1 + 1 < this.value.length) {
7128-
output.add(' ');
7158+
if (i_1 + 1 < this.value.length && !(this.value[i_1 + 1] instanceof Anonymous) ||
7159+
this.value[i_1 + 1] instanceof Anonymous && this.value[i_1 + 1].value !== ',') {
7160+
output.add(' ');
7161+
}
71297162
}
71307163
}
71317164
},
@@ -9945,6 +9978,29 @@
99459978
}
99469979
};
99479980

9981+
var styleExpression = function (args) {
9982+
var _this = this;
9983+
args = Array.prototype.slice.call(args);
9984+
switch (args.length) {
9985+
case 0: throw { type: 'Argument', message: 'one or more arguments required' };
9986+
}
9987+
var entityList = [new Variable(args[0].value, this.index, this.currentFileInfo).eval(this.context)];
9988+
args = entityList.map(function (a) { return a.toCSS(_this.context); }).join(this.context.compress ? ',' : ', ');
9989+
return new Variable("style(" + args + ")");
9990+
};
9991+
var style$1 = {
9992+
style: function () {
9993+
var args = [];
9994+
for (var _i = 0; _i < arguments.length; _i++) {
9995+
args[_i] = arguments[_i];
9996+
}
9997+
try {
9998+
return styleExpression.call(this, args);
9999+
}
10000+
catch (e) { }
10001+
},
10002+
};
10003+
994810004
var functions = (function (environment) {
994910005
var functions = { functionRegistry: functionRegistry, functionCaller: functionCaller };
995010006
// register functions
@@ -9959,6 +10015,7 @@
995910015
functionRegistry.addMultiple(string);
996010016
functionRegistry.addMultiple(svg());
996110017
functionRegistry.addMultiple(types);
10018+
functionRegistry.addMultiple(style$1);
996210019
return functions;
996310020
});
996410021

packages/less/dist/less.min.js

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/less/dist/less.min.js.map

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/less/src/less/functions/index.js

+2
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import number from './number';
1212
import string from './string';
1313
import svg from './svg';
1414
import types from './types';
15+
import style from './style';
1516

1617
export default environment => {
1718
const functions = { functionRegistry, functionCaller };
@@ -28,6 +29,7 @@ export default environment => {
2829
functionRegistry.addMultiple(string);
2930
functionRegistry.addMultiple(svg(environment));
3031
functionRegistry.addMultiple(types);
32+
functionRegistry.addMultiple(style);
3133

3234
return functions;
3335
};
+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
import Variable from '../tree/variable';
2+
import Anonymous from '../tree/variable';
3+
4+
const styleExpression = function (args) {
5+
args = Array.prototype.slice.call(args);
6+
switch (args.length) {
7+
case 0: throw { type: 'Argument', message: 'one or more arguments required' };
8+
}
9+
10+
const entityList = [new Variable(args[0].value, this.index, this.currentFileInfo).eval(this.context)];
11+
12+
args = entityList.map(a => { return a.toCSS(this.context); }).join(this.context.compress ? ',' : ', ');
13+
14+
return new Anonymous(`style(${args})`);
15+
};
16+
17+
export default {
18+
style: function(...args) {
19+
try {
20+
return styleExpression.call(this, args);
21+
} catch (e) {}
22+
},
23+
};

packages/less/src/less/parser/parser.js

+41-1
Original file line numberDiff line numberDiff line change
@@ -451,6 +451,42 @@ const Parser = function Parser(context, imports, fileInfo, currentIndex) {
451451
return new(tree.Call)(name, args, index + currentIndex, fileInfo);
452452
},
453453

454+
declarationCall: function () {
455+
let validCall;
456+
let args;
457+
const index = parserInput.i;
458+
459+
parserInput.save();
460+
461+
validCall = parserInput.$re(/^[\w]+\(/);
462+
if (!validCall) {
463+
parserInput.forget();
464+
return;
465+
}
466+
467+
validCall = validCall.substring(0, validCall.length - 1);
468+
469+
let rule = this.ruleProperty();
470+
let value;
471+
472+
if (rule) {
473+
value = this.value();
474+
}
475+
476+
if (rule && value) {
477+
args = [new (tree.Declaration)(rule, value, null, null, parserInput.i + currentIndex, fileInfo, true)];
478+
}
479+
480+
if (!parserInput.$char(')')) {
481+
parserInput.restore('Could not parse call arguments or missing \')\'');
482+
return;
483+
}
484+
485+
parserInput.forget();
486+
487+
return new(tree.Call)(validCall, args, index + currentIndex, fileInfo);
488+
},
489+
454490
//
455491
// Parsing rules for functions with non-standard args, e.g.:
456492
//
@@ -1625,6 +1661,10 @@ const Parser = function Parser(context, imports, fileInfo, currentIndex) {
16251661
if (e) {
16261662
value.push(e);
16271663
}
1664+
if (parserInput.peek(',')) {
1665+
value.push(new (tree.Anonymous)(',', parserInput.i));
1666+
parserInput.$char(',');
1667+
}
16281668
} while (e);
16291669

16301670
done = testCurrentChar();
@@ -1761,7 +1801,7 @@ const Parser = function Parser(context, imports, fileInfo, currentIndex) {
17611801
let rangeP;
17621802
parserInput.save();
17631803
do {
1764-
e = entities.keyword() || entities.variable() || entities.mixinLookup();
1804+
e = entities.declarationCall.bind(this)() || entities.keyword() || entities.variable() || entities.mixinLookup()
17651805
if (e) {
17661806
nodes.push(e);
17671807
} else if (parserInput.$char('(')) {

packages/less/src/less/tree/expression.js

+6-2
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import Node from './node';
22
import Paren from './paren';
33
import Comment from './comment';
44
import Dimension from './dimension';
5+
import Anonymous from './anonymous';
56

67
const Expression = function(value, noSpacing) {
78
this.value = value;
@@ -45,7 +46,7 @@ Expression.prototype = Object.assign(new Node(), {
4546
if (inParenthesis) {
4647
context.outOfParenthesis();
4748
}
48-
if (this.parens && this.parensInOp && !mathOn && !doubleParen
49+
if (this.parens && this.parensInOp && !mathOn && !doubleParen
4950
&& (!(returnValue instanceof Dimension))) {
5051
returnValue = new Paren(returnValue);
5152
}
@@ -56,7 +57,10 @@ Expression.prototype = Object.assign(new Node(), {
5657
for (let i = 0; i < this.value.length; i++) {
5758
this.value[i].genCSS(context, output);
5859
if (!this.noSpacing && i + 1 < this.value.length) {
59-
output.add(' ');
60+
if (i + 1 < this.value.length && !(this.value[i + 1] instanceof Anonymous) ||
61+
this.value[i + 1] instanceof Anonymous && this.value[i + 1].value !== ',') {
62+
output.add(' ');
63+
}
6064
}
6165
}
6266
},

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

+2-2
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
border: 1px solid grey;
2424
}
2525
}
26-
@container size (min-width: 60ch) {
26+
@container size(min-width: 60ch) {
2727
.article--post header {
2828
grid-template-areas: "avatar name" "avatar headline";
2929
align-items: start;
@@ -118,7 +118,7 @@
118118
margin: 0.5em 0 0 0;
119119
}
120120
}
121-
@container card (inline-size > 30em) and style (--responsive: true) {
121+
@container card (inline-size > 30em) and style(--responsive: true) {
122122
.card-content {
123123
grid-template-columns: 1fr 2fr;
124124
grid-template-rows: auto 1fr;

0 commit comments

Comments
 (0)