gruntjs/grunt-contrib-less — pull request #96 by kolya-ay (2013-11-14 16:46:10+00:00)
Title: Allow custom functions return types defined within less

It's usefull to allow custom functions to return not only primitive types. `less.tree.Anonymous` does not allow further processing of returned value. For example I wrote function `image-width` and want to set `margin-left: image-width('kitty.jpg') / 2`.

I could be achived by hardcoding allowed types (according to [parser](https://github.com/less/less.js/blob/master/lib/less/parser.js#L1106) [rules](https://github.com/less/less.js/blob/master/lib/less/parser.js#L719)) like this:

less.tree.functions[name.toLowerCase()] = function() {
var args = [].slice.call(arguments);
args.unshift(less);
var res = options.customFunctions[name].apply(this, args);
return ['Dimension', 'Color', 'URL', 'Quoted'].some(function (type) {
return res instanceof less.tree[type];
}) ? res : new less.tree.Anonymous(res);
};

Though it's much simplier (and acceptable I believe) to test existence of `toCSS`/`genCSS` methods.