Skip to content

Commit aa60398

Browse files
committedDec 10, 2023
fix(issue less#4235) style must not have space
fixes issue less#4235 where container query style would have invalid space after keyword
1 parent af51cc8 commit aa60398

File tree

10 files changed

+170
-9
lines changed

10 files changed

+170
-9
lines changed
 

‎dist/less.js

+51-1
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
//
@@ -4837,7 +4863,7 @@
48374863
var rangeP;
48384864
parserInput.save();
48394865
do {
4840-
e = entities.keyword() || entities.variable() || entities.mixinLookup();
4866+
e = entities.declarationCall.bind(this)() || entities.keyword() || entities.variable() || entities.mixinLookup();
48414867
if (e) {
48424868
nodes.push(e);
48434869
}
@@ -9952,6 +9978,29 @@
99529978
}
99539979
};
99549980

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+
995510004
var functions = (function (environment) {
995610005
var functions = { functionRegistry: functionRegistry, functionCaller: functionCaller };
995710006
// register functions
@@ -9966,6 +10015,7 @@
996610015
functionRegistry.addMultiple(string);
996710016
functionRegistry.addMultiple(svg());
996810017
functionRegistry.addMultiple(types);
10018+
functionRegistry.addMultiple(style$1);
996910019
return functions;
997010020
});
997110021

‎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

+51-1
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
//
@@ -4837,7 +4863,7 @@
48374863
var rangeP;
48384864
parserInput.save();
48394865
do {
4840-
e = entities.keyword() || entities.variable() || entities.mixinLookup();
4866+
e = entities.declarationCall.bind(this)() || entities.keyword() || entities.variable() || entities.mixinLookup();
48414867
if (e) {
48424868
nodes.push(e);
48434869
}
@@ -9952,6 +9978,29 @@
99529978
}
99539979
};
99549980

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+
995510004
var functions = (function (environment) {
995610005
var functions = { functionRegistry: functionRegistry, functionCaller: functionCaller };
995710006
// register functions
@@ -9966,6 +10015,7 @@
996610015
functionRegistry.addMultiple(string);
996710016
functionRegistry.addMultiple(svg());
996810017
functionRegistry.addMultiple(types);
10018+
functionRegistry.addMultiple(style$1);
996910019
return functions;
997010020
});
997110021

‎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

+37-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
//
@@ -1765,7 +1801,7 @@ const Parser = function Parser(context, imports, fileInfo, currentIndex) {
17651801
let rangeP;
17661802
parserInput.save();
17671803
do {
1768-
e = entities.keyword() || entities.variable() || entities.mixinLookup();
1804+
e = entities.declarationCall.bind(this)() || entities.keyword() || entities.variable() || entities.mixinLookup()
17691805
if (e) {
17701806
nodes.push(e);
17711807
} else if (parserInput.$char('(')) {

‎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)
Please sign in to comment.