Skip to content

Commit

Permalink
fix(issue #4235) style must not have space
Browse files Browse the repository at this point in the history
fixes issue #4235 where container query style would have invalid space
after keyword
  • Loading branch information
puckowski committed Dec 10, 2023
1 parent af51cc8 commit aa60398
Show file tree
Hide file tree
Showing 10 changed files with 170 additions and 9 deletions.
52 changes: 51 additions & 1 deletion dist/less.js
Original file line number Diff line number Diff line change
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 @@ -4837,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 @@ -9952,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 @@ -9966,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.

52 changes: 51 additions & 1 deletion packages/less/dist/less.js
Original file line number Diff line number Diff line change
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 @@ -4837,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 @@ -9952,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 @@ -9966,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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
@@ -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) {}
},
};
38 changes: 37 additions & 1 deletion packages/less/src/less/parser/parser.js
Original file line number Diff line number Diff line change
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 @@ -1765,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
4 changes: 2 additions & 2 deletions packages/test-data/css/_main/container.css
Original file line number Diff line number Diff line change
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 aa60398

Please sign in to comment.