fix 'File not found' import error

This commit is contained in:
Alexis Sellier
2012-01-10 23:52:45 +01:00
parent 7eb079dcdf
commit 2cc1b018fe
3 changed files with 13 additions and 9 deletions

View File

@@ -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" });
}
}

View File

@@ -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);
}
}
},

View File

@@ -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)([], []);
});
}
};