diff --git a/lib/less/visitors/import-sequencer.js b/lib/less/visitors/import-sequencer.js index 6fb46399..779faf9e 100644 --- a/lib/less/visitors/import-sequencer.js +++ b/lib/less/visitors/import-sequencer.js @@ -1,5 +1,6 @@ function ImportSequencer(onSequencerEmpty) { this.imports = []; + this.variableImports = []; this._onSequencerEmpty = onSequencerEmpty; } @@ -18,14 +19,26 @@ ImportSequencer.prototype.addImport = function(callback) { }; }; +ImportSequencer.prototype.addVariableImport = function(callback) { + this.variableImports.push(callback); +}; + ImportSequencer.prototype.tryRun = function() { - while(this.imports.length > 0) { - var importItem = this.imports[0]; - if (!importItem.isReady) { - return; + while(true) { + while(this.imports.length > 0) { + var importItem = this.imports[0]; + if (!importItem.isReady) { + return; + } + this.imports = this.imports.slice(1); + importItem.callback.apply(null, importItem.args); } - this.imports = this.imports.slice(1); - importItem.callback.apply(null, importItem.args); + if (this.variableImports.length === 0) { + break; + } + var variableImport = this.variableImports[0]; + this.variableImports = this.variableImports.slice(1); + variableImport(); } if (this._onSequencerEmpty) { this._onSequencerEmpty(); diff --git a/lib/less/visitors/import-visitor.js b/lib/less/visitors/import-visitor.js index b19ec7a9..9b8e4b22 100644 --- a/lib/less/visitors/import-visitor.js +++ b/lib/less/visitors/import-visitor.js @@ -27,6 +27,7 @@ ImportVisitor.prototype = { } this.isFinished = true; + this._sequencer.tryRun(); if (this.importCount === 0) { this._finish(error || this.error); } @@ -113,9 +114,13 @@ ImportVisitor.prototype = { var subFinish = function(e) { importVisitor.importCount--; - if (importVisitor.importCount === 0 && importVisitor.isFinished) { - importVisitor._finish(e || importVisitor.error); - } else if (e) { + if (importVisitor.isFinished) { + this._sequencer.tryRun(); + if (importVisitor.importCount === 0) { + importVisitor._finish(e || importVisitor.error); + } + } + if (e) { importVisitor.error = e; } };