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 issues #4235 wgere container query style would have invalid
space after keyword
  • Loading branch information
puckowski committed Dec 10, 2023
1 parent 6c3ecb7 commit 90379d6
Show file tree
Hide file tree
Showing 10 changed files with 172 additions and 25 deletions.
59 changes: 52 additions & 7 deletions 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 @@ -4879,12 +4905,7 @@
} while (e);
parserInput.forget();
if (nodes.length > 0) {
if (nodes[0] && (nodes[0] instanceof tree.Keyword) && nodes[0].value === 'style') {
return new (tree.Expression)(nodes, true);
}
else {
return new (tree.Expression)(nodes);
}
return new (tree.Expression)(nodes);
}
},
mediaFeatures: function (syntaxOptions) {
Expand Down Expand Up @@ -9957,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 @@ -9971,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.

59 changes: 52 additions & 7 deletions 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 @@ -4879,12 +4905,7 @@
} while (e);
parserInput.forget();
if (nodes.length > 0) {
if (nodes[0] && (nodes[0] instanceof tree.Keyword) && nodes[0].value === 'style') {
return new (tree.Expression)(nodes, true);
}
else {
return new (tree.Expression)(nodes);
}
return new (tree.Expression)(nodes);
}
},
mediaFeatures: function (syntaxOptions) {
Expand Down Expand Up @@ -9957,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 @@ -9971,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) {}
},
};
44 changes: 38 additions & 6 deletions 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 Expand Up @@ -1803,11 +1839,7 @@ const Parser = function Parser(context, imports, fileInfo, currentIndex) {

parserInput.forget();
if (nodes.length > 0) {
if (nodes[0] && (nodes[0] instanceof tree.Keyword) && nodes[0].value === 'style') {
return new(tree.Expression)(nodes, true)
} else {
return new(tree.Expression)(nodes);
}
return new(tree.Expression)(nodes);
}
},

Expand Down
2 changes: 1 addition & 1 deletion 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

0 comments on commit 90379d6

Please sign in to comment.