lib/less/js/lib/less/index.js in less-2.0.8 vs lib/less/js/lib/less/index.js in less-2.0.9
- old
+ new
@@ -1,11 +1,11 @@
var path = require('path'),
sys = require('util'),
fs = require('fs');
var less = {
- version: [1, 1, 5],
+ version: [1, 2, 1],
Parser: require('./parser').Parser,
importer: require('./parser').importer,
tree: require('./tree'),
render: function (input, options, callback) {
options = options || {};
@@ -41,46 +41,50 @@
var error = [];
var stylize = options.color ? less.stylize : function (str) { return str };
if (options.silent) { return }
- if (!ctx.index) {
+ if (ctx.stack) { return sys.error(stylize(ctx.stack, 'red')) }
+
+ if (!ctx.hasOwnProperty('index')) {
return sys.error(ctx.stack || ctx.message);
}
if (typeof(extract[0]) === 'string') {
error.push(stylize((ctx.line - 1) + ' ' + extract[0], 'grey'));
}
- error.push(ctx.line + ' ' + extract[1].slice(0, ctx.column)
- + stylize(stylize(extract[1][ctx.column], 'bold')
- + extract[1].slice(ctx.column + 1), 'yellow'));
+ if (extract[1]) {
+ error.push(ctx.line + ' ' + extract[1].slice(0, ctx.column)
+ + stylize(stylize(stylize(extract[1][ctx.column], 'bold')
+ + extract[1].slice(ctx.column + 1), 'red'), 'inverse'));
+ }
if (typeof(extract[2]) === 'string') {
error.push(stylize((ctx.line + 1) + ' ' + extract[2], 'grey'));
}
error = error.join('\n') + '\033[0m\n';
- message += stylize(ctx.message, 'red');
- ctx.filename && (message += stylize(' in ', 'red') + ctx.filename);
+ message += stylize(ctx.type + 'Error: ' + ctx.message, 'red');
+ ctx.filename && (message += stylize(' in ', 'red') + ctx.filename +
+ stylize(':' + ctx.line + ':' + ctx.column, 'grey'));
sys.error(message, error);
if (ctx.callLine) {
sys.error(stylize('from ', 'red') + (ctx.filename || ''));
sys.error(stylize(ctx.callLine, 'grey') + ' ' + ctx.callExtract);
}
- if (ctx.stack) { sys.error(stylize(ctx.stack, 'red')) }
}
};
-['color', 'directive', 'operation', 'dimension',
- 'keyword', 'variable', 'ruleset', 'element',
- 'selector', 'quoted', 'expression', 'rule',
- 'call', 'url', 'alpha', 'import',
- 'mixin', 'comment', 'anonymous', 'value',
- 'javascript', 'assignment'
+['color', 'directive', 'operation', 'dimension',
+ 'keyword', 'variable', 'ruleset', 'element',
+ 'selector', 'quoted', 'expression', 'rule',
+ 'call', 'url', 'alpha', 'import',
+ 'mixin', 'comment', 'anonymous', 'value',
+ 'javascript', 'assignment', 'condition', 'paren'
].forEach(function (n) {
require('./tree/' + n);
});
less.Parser.importer = function (file, paths, callback) {
@@ -104,20 +108,19 @@
new(less.Parser)({
paths: [path.dirname(pathname)].concat(paths),
filename: pathname
}).parse(data, function (e, root) {
- if (e) less.writeError(e);
- callback(root);
+ callback(e, root, data);
});
});
} else {
- sys.error("file '" + file + "' wasn't found.\n");
- process.exit(1);
+ callback({ type: 'File', message: "'" + file + "' wasn't found.\n" });
}
}
require('./functions');
+require('./colors');
for (var k in less) { exports[k] = less[k] }
// Stylize a string
function stylize(str, style) {