cloudhead/less.js — pull request #576 by hokaccha (2012-01-17 05:55:35+00:00)
Title: Fix `parser.parse` and `less.render` error handling

`less.render` or `parser.parse` error handling differs by 'parse error' and 'synatax error'. Because 'parse error' is set callback, 'syntax error' throw exception.

var parser = new less.Parser;
try {
parser.parse('.class width: { 1 + 1 ', function(err, css) {
console.log('parse error:' + err);
});
} catch (e) {
console.log('syntax error:' + e);
}

Error handling is duplicated.

`parser.parse` is not asynchronized function. It should return value, not use callback.

var parser = new less.Parser;
var tree, css;
try {
tree = parser.parse(str);
css = tree.toCSS();
} catch (e) {
console.log(e);
}

And for backward compatibility, It also use the callback style.