Skip to content

Commit 90379d6

Browse files
committed
fix*issue less#4235) style must not have space
fixes issues less#4235 wgere container query style would have invalid space after keyword
1 parent 6c3ecb7 commit 90379d6

File tree

10 files changed

+172
-25
lines changed

10 files changed

+172
-25
lines changed

dist/less.js

+52-7
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
}
@@ -4879,12 +4905,7 @@
48794905
} while (e);
48804906
parserInput.forget();
48814907
if (nodes.length > 0) {
4882-
if (nodes[0] && (nodes[0] instanceof tree.Keyword) && nodes[0].value === 'style') {
4883-
return new (tree.Expression)(nodes, true);
4884-
}
4885-
else {
4886-
return new (tree.Expression)(nodes);
4887-
}
4908+
return new (tree.Expression)(nodes);
48884909
}
48894910
},
48904911
mediaFeatures: function (syntaxOptions) {
@@ -9957,6 +9978,29 @@
99579978
}
99589979
};
99599980

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+
996010004
var functions = (function (environment) {
996110005
var functions = { functionRegistry: functionRegistry, functionCaller: functionCaller };
996210006
// register functions
@@ -9971,6 +10015,7 @@
997110015
functionRegistry.addMultiple(string);
997210016
functionRegistry.addMultiple(svg());
997310017
functionRegistry.addMultiple(types);
10018+
functionRegistry.addMultiple(style$1);
997410019
return functions;
997510020
});
997610021

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

+52-7
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
}
@@ -4879,12 +4905,7 @@
48794905
} while (e);
48804906
parserInput.forget();
48814907
if (nodes.length > 0) {
4882-
if (nodes[0] && (nodes[0] instanceof tree.Keyword) && nodes[0].value === 'style') {
4883-
return new (tree.Expression)(nodes, true);
4884-
}
4885-
else {
4886-
return new (tree.Expression)(nodes);
4887-
}
4908+
return new (tree.Expression)(nodes);
48884909
}
48894910
},
48904911
mediaFeatures: function (syntaxOptions) {
@@ -9957,6 +9978,29 @@
99579978
}
99589979
};
99599980

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+
996010004
var functions = (function (environment) {
996110005
var functions = { functionRegistry: functionRegistry, functionCaller: functionCaller };
996210006
// register functions
@@ -9971,6 +10015,7 @@
997110015
functionRegistry.addMultiple(string);
997210016
functionRegistry.addMultiple(svg());
997310017
functionRegistry.addMultiple(types);
10018+
functionRegistry.addMultiple(style$1);
997410019
return functions;
997510020
});
997610021

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

+38-6
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('(')) {
@@ -1803,11 +1839,7 @@ const Parser = function Parser(context, imports, fileInfo, currentIndex) {
18031839

18041840
parserInput.forget();
18051841
if (nodes.length > 0) {
1806-
if (nodes[0] && (nodes[0] instanceof tree.Keyword) && nodes[0].value === 'style') {
1807-
return new(tree.Expression)(nodes, true)
1808-
} else {
1809-
return new(tree.Expression)(nodes);
1810-
}
1842+
return new(tree.Expression)(nodes);
18111843
}
18121844
},
18131845

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

+1-1
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;

0 commit comments

Comments
 (0)