mirror of
https://github.com/less/less.js.git
synced 2026-01-23 22:27:57 -05:00
Sequencer working so imports are always processed in the same order
This commit is contained in:
@@ -12,7 +12,7 @@ ImportSequencer.prototype.addImport = function(callback) {
|
||||
};
|
||||
this.imports.push(importItem);
|
||||
return function() {
|
||||
importItem.args = [].concat(arguments);
|
||||
importItem.args = Array.prototype.slice.call(arguments, 0);
|
||||
importItem.isReady = true;
|
||||
importSequencer.tryRun();
|
||||
};
|
||||
@@ -32,4 +32,4 @@ ImportSequencer.prototype.tryRun = function() {
|
||||
}
|
||||
};
|
||||
|
||||
module.exports = ImportSequencer;
|
||||
module.exports = ImportSequencer;
|
||||
|
||||
@@ -17,31 +17,28 @@ var ImportVisitor = function(importer, finish, evalEnv, onceFileDetectionMap, re
|
||||
}
|
||||
}
|
||||
}
|
||||
this._sequencer = new ImportSequencer(this._onSequencerEmpty.bind(this));
|
||||
this._sequencer = new ImportSequencer();
|
||||
};
|
||||
|
||||
ImportVisitor.prototype = {
|
||||
isReplacing: true,
|
||||
_onSequencerEmpty: function() {
|
||||
if (this.isFinished) {
|
||||
this._finish(this.error);
|
||||
}
|
||||
},
|
||||
run: function (root) {
|
||||
var error;
|
||||
try {
|
||||
// process the contents
|
||||
this._visitor.visit(root);
|
||||
}
|
||||
catch(e) {
|
||||
this.error = e;
|
||||
error = e;
|
||||
}
|
||||
|
||||
this.isFinished = true;
|
||||
this._sequencer.tryRun();
|
||||
if (this.importCount === 0) {
|
||||
this._finish(error);
|
||||
}
|
||||
},
|
||||
visitImport: function (importNode, visitArgs) {
|
||||
var importVisitor = this,
|
||||
evaldImportNode,
|
||||
var evaldImportNode,
|
||||
inlineCSS = importNode.options.inline;
|
||||
|
||||
if (!importNode.css || inlineCSS) {
|
||||
@@ -67,53 +64,61 @@ ImportVisitor.prototype = {
|
||||
|
||||
// try appending if we haven't determined if it is css or not
|
||||
var tryAppendLessExtension = importNode.css === undefined;
|
||||
this._importer.push(importNode.getPath(), tryAppendLessExtension, importNode.currentFileInfo, importNode.options, function (e, root, importedAtRoot, fullPath) {
|
||||
if (e && !e.filename) {
|
||||
e.index = importNode.index; e.filename = importNode.currentFileInfo.filename;
|
||||
}
|
||||
|
||||
var duplicateImport = importedAtRoot || fullPath in importVisitor.recursionDetector;
|
||||
if (!context.importMultiple) {
|
||||
if (duplicateImport) {
|
||||
importNode.skip = true;
|
||||
} else {
|
||||
importNode.skip = function() {
|
||||
if (fullPath in importVisitor.onceFileDetectionMap) {
|
||||
return true;
|
||||
}
|
||||
importVisitor.onceFileDetectionMap[fullPath] = true;
|
||||
return false;
|
||||
};
|
||||
}
|
||||
}
|
||||
var onImported = this.onImported.bind(this, importNode, context),
|
||||
sequencedOnImported = this._sequencer.addImport(onImported);
|
||||
|
||||
var subFinish = function(e) {
|
||||
importVisitor.importCount--;
|
||||
|
||||
if (importVisitor.importCount === 0 && importVisitor.isFinished) {
|
||||
importVisitor._finish(e);
|
||||
}
|
||||
};
|
||||
|
||||
if (root) {
|
||||
importNode.root = root;
|
||||
importNode.importedFilename = fullPath;
|
||||
|
||||
if (!inlineCSS && (context.importMultiple || !duplicateImport)) {
|
||||
importVisitor.recursionDetector[fullPath] = true;
|
||||
new ImportVisitor(importVisitor._importer, subFinish, context, importVisitor.onceFileDetectionMap, importVisitor.recursionDetector)
|
||||
.run(root);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
subFinish();
|
||||
});
|
||||
this._importer.push(importNode.getPath(), tryAppendLessExtension, importNode.currentFileInfo, importNode.options, sequencedOnImported);
|
||||
}
|
||||
}
|
||||
visitArgs.visitDeeper = false;
|
||||
return importNode;
|
||||
},
|
||||
onImported: function (importNode, context, e, root, importedAtRoot, fullPath) {
|
||||
if (e && !e.filename) {
|
||||
e.index = importNode.index; e.filename = importNode.currentFileInfo.filename;
|
||||
}
|
||||
|
||||
var importVisitor = this,
|
||||
inlineCSS = importNode.options.inline,
|
||||
duplicateImport = importedAtRoot || fullPath in importVisitor.recursionDetector;
|
||||
|
||||
if (!context.importMultiple) {
|
||||
if (duplicateImport) {
|
||||
importNode.skip = true;
|
||||
} else {
|
||||
importNode.skip = function() {
|
||||
if (fullPath in importVisitor.onceFileDetectionMap) {
|
||||
return true;
|
||||
}
|
||||
importVisitor.onceFileDetectionMap[fullPath] = true;
|
||||
return false;
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
var subFinish = function(e) {
|
||||
importVisitor.importCount--;
|
||||
|
||||
if (importVisitor.importCount === 0 && importVisitor.isFinished) {
|
||||
importVisitor._finish(e);
|
||||
}
|
||||
};
|
||||
|
||||
if (root) {
|
||||
importNode.root = root;
|
||||
importNode.importedFilename = fullPath;
|
||||
|
||||
if (!inlineCSS && (context.importMultiple || !duplicateImport)) {
|
||||
importVisitor.recursionDetector[fullPath] = true;
|
||||
new ImportVisitor(importVisitor._importer, subFinish, context, importVisitor.onceFileDetectionMap, importVisitor.recursionDetector)
|
||||
.run(root);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
subFinish();
|
||||
},
|
||||
visitRule: function (ruleNode, visitArgs) {
|
||||
visitArgs.visitDeeper = false;
|
||||
return ruleNode;
|
||||
|
||||
Reference in New Issue
Block a user