Skip to content

Commit

Permalink
Master container style fix for 4235 (#4237)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
puckowski committed Jan 18, 2024
1 parent 13864a6 commit 53f84f0
Show file tree
Hide file tree
Showing 11 changed files with 196 additions and 13 deletions.
61 changes: 59 additions & 2 deletions dist/less.js
Expand Up @@ -3622,6 +3622,32 @@
parserInput.forget();
return new (tree.Call)(name, args, index + currentIndex, fileInfo);
},
declarationCall: function () {
var validCall;
var args;
var index = parserInput.i;
parserInput.save();
validCall = parserInput.$re(/^[\w]+\(/);
if (!validCall) {
parserInput.forget();
return;
}
validCall = validCall.substring(0, validCall.length - 1);
var rule = this.ruleProperty();
var value;
if (rule) {
value = this.value();
}
if (rule && value) {
args = [new (tree.Declaration)(rule, value, null, null, parserInput.i + currentIndex, fileInfo, true)];
}
if (!parserInput.$char(')')) {
parserInput.restore('Could not parse call arguments or missing \')\'');
return;
}
parserInput.forget();
return new (tree.Call)(validCall, args, index + currentIndex, fileInfo);
},
//
// Parsing rules for functions with non-standard args, e.g.:
//
Expand Down Expand Up @@ -4706,6 +4732,10 @@
if (e) {
value.push(e);
}
if (parserInput.peek(',')) {
value.push(new (tree.Anonymous)(',', parserInput.i));
parserInput.$char(',');
}
} while (e);
done = testCurrentChar();
if (value.length > 0) {
Expand Down Expand Up @@ -4833,7 +4863,7 @@
var rangeP;
parserInput.save();
do {
e = entities.keyword() || entities.variable() || entities.mixinLookup();
e = entities.declarationCall.bind(this)() || entities.keyword() || entities.variable() || entities.mixinLookup();
if (e) {
nodes.push(e);
}
Expand Down Expand Up @@ -7125,7 +7155,10 @@
for (var i_1 = 0; i_1 < this.value.length; i_1++) {
this.value[i_1].genCSS(context, output);
if (!this.noSpacing && i_1 + 1 < this.value.length) {
output.add(' ');
if (i_1 + 1 < this.value.length && !(this.value[i_1 + 1] instanceof Anonymous) ||
this.value[i_1 + 1] instanceof Anonymous && this.value[i_1 + 1].value !== ',') {
output.add(' ');
}
}
}
},
Expand Down Expand Up @@ -9945,6 +9978,29 @@
}
};

var styleExpression = function (args) {
var _this = this;
args = Array.prototype.slice.call(args);
switch (args.length) {
case 0: throw { type: 'Argument', message: 'one or more arguments required' };
}
var entityList = [new Variable(args[0].value, this.index, this.currentFileInfo).eval(this.context)];
args = entityList.map(function (a) { return a.toCSS(_this.context); }).join(this.context.compress ? ',' : ', ');
return new Variable("style(" + args + ")");
};
var style$1 = {
style: function () {
var args = [];
for (var _i = 0; _i < arguments.length; _i++) {
args[_i] = arguments[_i];
}
try {
return styleExpression.call(this, args);
}
catch (e) { }
},
};

var functions = (function (environment) {
var functions = { functionRegistry: functionRegistry, functionCaller: functionCaller };
// register functions
Expand All @@ -9959,6 +10015,7 @@
functionRegistry.addMultiple(string);
functionRegistry.addMultiple(svg());
functionRegistry.addMultiple(types);
functionRegistry.addMultiple(style$1);
return functions;
});

Expand Down
2 changes: 1 addition & 1 deletion dist/less.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/less.min.js.map

Large diffs are not rendered by default.

61 changes: 59 additions & 2 deletions packages/less/dist/less.js
Expand Up @@ -3622,6 +3622,32 @@
parserInput.forget();
return new (tree.Call)(name, args, index + currentIndex, fileInfo);
},
declarationCall: function () {
var validCall;
var args;
var index = parserInput.i;
parserInput.save();
validCall = parserInput.$re(/^[\w]+\(/);
if (!validCall) {
parserInput.forget();
return;
}
validCall = validCall.substring(0, validCall.length - 1);
var rule = this.ruleProperty();
var value;
if (rule) {
value = this.value();
}
if (rule && value) {
args = [new (tree.Declaration)(rule, value, null, null, parserInput.i + currentIndex, fileInfo, true)];
}
if (!parserInput.$char(')')) {
parserInput.restore('Could not parse call arguments or missing \')\'');
return;
}
parserInput.forget();
return new (tree.Call)(validCall, args, index + currentIndex, fileInfo);
},
//
// Parsing rules for functions with non-standard args, e.g.:
//
Expand Down Expand Up @@ -4706,6 +4732,10 @@
if (e) {
value.push(e);
}
if (parserInput.peek(',')) {
value.push(new (tree.Anonymous)(',', parserInput.i));
parserInput.$char(',');
}
} while (e);
done = testCurrentChar();
if (value.length > 0) {
Expand Down Expand Up @@ -4833,7 +4863,7 @@
var rangeP;
parserInput.save();
do {
e = entities.keyword() || entities.variable() || entities.mixinLookup();
e = entities.declarationCall.bind(this)() || entities.keyword() || entities.variable() || entities.mixinLookup();
if (e) {
nodes.push(e);
}
Expand Down Expand Up @@ -7125,7 +7155,10 @@
for (var i_1 = 0; i_1 < this.value.length; i_1++) {
this.value[i_1].genCSS(context, output);
if (!this.noSpacing && i_1 + 1 < this.value.length) {
output.add(' ');
if (i_1 + 1 < this.value.length && !(this.value[i_1 + 1] instanceof Anonymous) ||
this.value[i_1 + 1] instanceof Anonymous && this.value[i_1 + 1].value !== ',') {
output.add(' ');
}
}
}
},
Expand Down Expand Up @@ -9945,6 +9978,29 @@
}
};

var styleExpression = function (args) {
var _this = this;
args = Array.prototype.slice.call(args);
switch (args.length) {
case 0: throw { type: 'Argument', message: 'one or more arguments required' };
}
var entityList = [new Variable(args[0].value, this.index, this.currentFileInfo).eval(this.context)];
args = entityList.map(function (a) { return a.toCSS(_this.context); }).join(this.context.compress ? ',' : ', ');
return new Variable("style(" + args + ")");
};
var style$1 = {
style: function () {
var args = [];
for (var _i = 0; _i < arguments.length; _i++) {
args[_i] = arguments[_i];
}
try {
return styleExpression.call(this, args);
}
catch (e) { }
},
};

var functions = (function (environment) {
var functions = { functionRegistry: functionRegistry, functionCaller: functionCaller };
// register functions
Expand All @@ -9959,6 +10015,7 @@
functionRegistry.addMultiple(string);
functionRegistry.addMultiple(svg());
functionRegistry.addMultiple(types);
functionRegistry.addMultiple(style$1);
return functions;
});

Expand Down
2 changes: 1 addition & 1 deletion packages/less/dist/less.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion packages/less/dist/less.min.js.map

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions packages/less/src/less/functions/index.js
Expand Up @@ -12,6 +12,7 @@ import number from './number';
import string from './string';
import svg from './svg';
import types from './types';
import style from './style';

export default environment => {
const functions = { functionRegistry, functionCaller };
Expand All @@ -28,6 +29,7 @@ export default environment => {
functionRegistry.addMultiple(string);
functionRegistry.addMultiple(svg(environment));
functionRegistry.addMultiple(types);
functionRegistry.addMultiple(style);

return functions;
};
23 changes: 23 additions & 0 deletions packages/less/src/less/functions/style.js
@@ -0,0 +1,23 @@
import Variable from '../tree/variable';
import Anonymous from '../tree/variable';

const styleExpression = function (args) {
args = Array.prototype.slice.call(args);
switch (args.length) {
case 0: throw { type: 'Argument', message: 'one or more arguments required' };
}

const entityList = [new Variable(args[0].value, this.index, this.currentFileInfo).eval(this.context)];

args = entityList.map(a => { return a.toCSS(this.context); }).join(this.context.compress ? ',' : ', ');

return new Anonymous(`style(${args})`);
};

export default {
style: function(...args) {
try {
return styleExpression.call(this, args);
} catch (e) {}
},
};
42 changes: 41 additions & 1 deletion packages/less/src/less/parser/parser.js
Expand Up @@ -451,6 +451,42 @@ const Parser = function Parser(context, imports, fileInfo, currentIndex) {
return new(tree.Call)(name, args, index + currentIndex, fileInfo);
},

declarationCall: function () {
let validCall;
let args;
const index = parserInput.i;

parserInput.save();

validCall = parserInput.$re(/^[\w]+\(/);
if (!validCall) {
parserInput.forget();
return;
}

validCall = validCall.substring(0, validCall.length - 1);

let rule = this.ruleProperty();
let value;

if (rule) {
value = this.value();
}

if (rule && value) {
args = [new (tree.Declaration)(rule, value, null, null, parserInput.i + currentIndex, fileInfo, true)];
}

if (!parserInput.$char(')')) {
parserInput.restore('Could not parse call arguments or missing \')\'');
return;
}

parserInput.forget();

return new(tree.Call)(validCall, args, index + currentIndex, fileInfo);
},

//
// Parsing rules for functions with non-standard args, e.g.:
//
Expand Down Expand Up @@ -1625,6 +1661,10 @@ const Parser = function Parser(context, imports, fileInfo, currentIndex) {
if (e) {
value.push(e);
}
if (parserInput.peek(',')) {
value.push(new (tree.Anonymous)(',', parserInput.i));
parserInput.$char(',');
}
} while (e);

done = testCurrentChar();
Expand Down Expand Up @@ -1761,7 +1801,7 @@ const Parser = function Parser(context, imports, fileInfo, currentIndex) {
let rangeP;
parserInput.save();
do {
e = entities.keyword() || entities.variable() || entities.mixinLookup();
e = entities.declarationCall.bind(this)() || entities.keyword() || entities.variable() || entities.mixinLookup()
if (e) {
nodes.push(e);
} else if (parserInput.$char('(')) {
Expand Down
8 changes: 6 additions & 2 deletions packages/less/src/less/tree/expression.js
Expand Up @@ -2,6 +2,7 @@ import Node from './node';
import Paren from './paren';
import Comment from './comment';
import Dimension from './dimension';
import Anonymous from './anonymous';

const Expression = function(value, noSpacing) {
this.value = value;
Expand Down Expand Up @@ -45,7 +46,7 @@ Expression.prototype = Object.assign(new Node(), {
if (inParenthesis) {
context.outOfParenthesis();
}
if (this.parens && this.parensInOp && !mathOn && !doubleParen
if (this.parens && this.parensInOp && !mathOn && !doubleParen
&& (!(returnValue instanceof Dimension))) {
returnValue = new Paren(returnValue);
}
Expand All @@ -56,7 +57,10 @@ Expression.prototype = Object.assign(new Node(), {
for (let i = 0; i < this.value.length; i++) {
this.value[i].genCSS(context, output);
if (!this.noSpacing && i + 1 < this.value.length) {
output.add(' ');
if (i + 1 < this.value.length && !(this.value[i + 1] instanceof Anonymous) ||
this.value[i + 1] instanceof Anonymous && this.value[i + 1].value !== ',') {
output.add(' ');
}
}
}
},
Expand Down
4 changes: 2 additions & 2 deletions packages/test-data/css/_main/container.css
Expand Up @@ -23,7 +23,7 @@
border: 1px solid grey;
}
}
@container size (min-width: 60ch) {
@container size(min-width: 60ch) {
.article--post header {
grid-template-areas: "avatar name" "avatar headline";
align-items: start;
Expand Down Expand Up @@ -118,7 +118,7 @@
margin: 0.5em 0 0 0;
}
}
@container card (inline-size > 30em) and style (--responsive: true) {
@container card (inline-size > 30em) and style(--responsive: true) {
.card-content {
grid-template-columns: 1fr 2fr;
grid-template-rows: auto 1fr;
Expand Down

0 comments on commit 53f84f0

Please sign in to comment.