improve errors from imported files

This commit is contained in:
Alexis Sellier
2012-01-09 20:39:24 +01:00
parent a067df6e19
commit 6d4516e6fc
3 changed files with 10 additions and 9 deletions

View File

@@ -110,8 +110,7 @@ less.Parser.importer = function (file, paths, callback) {
paths: [path.dirname(pathname)].concat(paths),
filename: pathname
}).parse(data, function (e, root) {
if (e) less.writeError(e);
callback(root);
callback(e, root);
});
});
} else {

View File

@@ -73,6 +73,7 @@ less.Parser = function Parser(env) {
queue: [], // Files which haven't been imported yet
files: {}, // Holds the imported parse trees
mime: env && env.mime, // MIME type of .less files
error: null, // Error in parsing/evaluating an import
push: function (path, callback) {
var that = this;
this.queue.push(path);
@@ -80,11 +81,12 @@ less.Parser = function Parser(env) {
//
// Import a file asynchronously
//
less.Parser.importer(path, this.paths, function (root) {
less.Parser.importer(path, this.paths, function (e, root) {
that.queue.splice(that.queue.indexOf(path), 1); // Remove the path from the queue
that.files[path] = root; // Store the root
callback(root);
if (e && !that.error) { that.error = e }
callback(e, root);
if (that.queue.length === 0) { finish() } // Call `finish` if we're done importing
}, env);
@@ -203,7 +205,7 @@ less.Parser = function Parser(env) {
this.type = e.type || 'SyntaxError';
this.message = e.message;
this.filename = env.filename;
this.filename = e.filename || env.filename;
this.index = e.index;
this.line = typeof(line) === 'number' ? line + 1 : null;
this.callLine = e.call && (getLocation(e.call) + 1);
@@ -364,6 +366,9 @@ less.Parser = function Parser(env) {
} catch (e) {
throw new(LessError)(e, env);
}
if (parser.imports.error) { throw parser.imports.error }
if (options.yuicompress && less.mode === 'node') {
return require('./cssmin').compressor.cssmin(css);
} else if (options.compress) {

View File

@@ -28,10 +28,7 @@ tree.Import = function (path, imports, features) {
// Only pre-compile .less files
if (! this.css) {
imports.push(this.path, function (root) {
if (! root) {
throw new(Error)("Error parsing " + that.path);
}
imports.push(this.path, function (e, root) {
that.root = root;
});
}