From 6d4516e6fcc6a84cbaf5db9e5753d05787a28937 Mon Sep 17 00:00:00 2001 From: Alexis Sellier Date: Mon, 9 Jan 2012 20:39:24 +0100 Subject: [PATCH] improve errors from imported files --- lib/less/index.js | 3 +-- lib/less/parser.js | 11 ++++++++--- lib/less/tree/import.js | 5 +---- 3 files changed, 10 insertions(+), 9 deletions(-) diff --git a/lib/less/index.js b/lib/less/index.js index 3bfabe75..8dd52f45 100644 --- a/lib/less/index.js +++ b/lib/less/index.js @@ -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 { diff --git a/lib/less/parser.js b/lib/less/parser.js index dc291d35..90752449 100644 --- a/lib/less/parser.js +++ b/lib/less/parser.js @@ -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) { diff --git a/lib/less/tree/import.js b/lib/less/tree/import.js index aa203b95..d86bee6b 100644 --- a/lib/less/tree/import.js +++ b/lib/less/tree/import.js @@ -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; }); }