Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -13,6 +13,7 @@ import string from './string';
import svg from './svg';
import types from './types';
import style from './style';
import size from './size';

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

return functions;
};
23 changes: 23 additions & 0 deletions packages/less/src/less/functions/size.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 sizeExpression = 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(`size(${args})`);
};

export default {
size: function(...args) {
try {
return sizeExpression.call(this, args);
} catch (e) {}
},
};
11 changes: 9 additions & 2 deletions packages/less/src/less/parser/parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -482,13 +482,20 @@ const Parser = function Parser(context, imports, fileInfo, currentIndex) {
const index = parserInput.i;

parserInput.save();


let keywordEntity = this.entities.keyword();
parserInput.restore();
parserInput.save();

validCall = parserInput.$re(/^[\w]+\(/);
if (!validCall) {
parserInput.forget();
return;
} else if (validCall && keywordEntity && !functionRegistry.get(validCall.substring(0, validCall.length - 1))) {
parserInput.restore();
return;
}

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

let rule = this.ruleProperty();
Expand Down
8 changes: 8 additions & 0 deletions packages/test-data/css/_main/media.css
Original file line number Diff line number Diff line change
Expand Up @@ -269,3 +269,11 @@
padding: 0;
}
}
@media screen and (max-width: 1280px) {
.form-process-table {
width: 1200px;
}
.form-process-table > div {
width: 960px;
}
}
9 changes: 9 additions & 0 deletions packages/test-data/less/_main/media.less
Original file line number Diff line number Diff line change
Expand Up @@ -297,3 +297,12 @@
}
}
}

@media screen and(max-width:1280px) {
.form-process-table {
width: 1200px;
> div {
width: 960px;
}
}
}