diff --git a/lib/less/index.js b/lib/less/index.js index 8dd52f45..75aea29f 100644 --- a/lib/less/index.js +++ b/lib/less/index.js @@ -114,8 +114,7 @@ less.Parser.importer = function (file, paths, callback) { }); }); } else { - sys.error("file '" + file + "' wasn't found.\n"); - process.exit(1); + callback({ type: 'File', message: "'" + file + "' wasn't found.\n" }); } } diff --git a/lib/less/parser.js b/lib/less/parser.js index d43ddbe0..b0982d68 100644 --- a/lib/less/parser.js +++ b/lib/less/parser.js @@ -194,7 +194,7 @@ less.Parser = function Parser(env) { n >= 0 && input.charAt(n) !== '\n'; n--) { column++ } - return { line: index ? (input.slice(0, index).match(/\n/g) || "").length : null, + return { line: typeof(index) === 'number' ? (input.slice(0, index).match(/\n/g) || "").length : null, column: column }; } @@ -330,7 +330,7 @@ less.Parser = function Parser(env) { var line, lines, column; return function (options, variables) { - var frames = []; + var frames = [], importError; options = options || {}; // @@ -368,7 +368,10 @@ less.Parser = function Parser(env) { throw new(LessError)(e, env); } - if (parser.imports.error) { throw parser.imports.error } + if ((importError = parser.imports.error)) { // Check if there was an error during importing + if (importError instanceof LessError) throw importError; + else throw new(LessError)(importError, env); + } if (options.yuicompress && less.mode === 'node') { return require('./cssmin').compressor.cssmin(css); @@ -1017,12 +1020,12 @@ less.Parser = function Parser(env) { // stored in `import`, which we pass to the Import constructor. // "import": function () { - var path, features; + var path, features, index = i; if ($(/^@import\s+/) && (path = $(this.entities.quoted) || $(this.entities.url))) { features = $(this.mediaFeatures); if ($(';')) { - return new(tree.Import)(path, imports, features); + return new(tree.Import)(path, imports, features, index); } } }, diff --git a/lib/less/tree/import.js b/lib/less/tree/import.js index d86bee6b..a099efd9 100644 --- a/lib/less/tree/import.js +++ b/lib/less/tree/import.js @@ -11,9 +11,10 @@ // `import,push`, we also pass it a callback, which it'll call once // the file has been fetched, and parsed. // -tree.Import = function (path, imports, features) { +tree.Import = function (path, imports, features, index) { var that = this; + this.index = index; this._path = path; this.features = features && new(tree.Value)(features); @@ -29,7 +30,8 @@ tree.Import = function (path, imports, features) { // Only pre-compile .less files if (! this.css) { imports.push(this.path, function (e, root) { - that.root = root; + if (e) { e.index = index } + that.root = root || new(tree.Ruleset)([], []); }); } };