mirror of
https://github.com/less/less.js.git
synced 2026-01-22 21:58:14 -05:00
Refactor out the processing of the import, ready to be done asyncronously
This commit is contained in:
@@ -32,8 +32,7 @@ ImportVisitor.prototype = {
|
||||
}
|
||||
},
|
||||
visitImport: function (importNode, visitArgs) {
|
||||
var evaldImportNode,
|
||||
inlineCSS = importNode.options.inline;
|
||||
var inlineCSS = importNode.options.inline;
|
||||
|
||||
if (!importNode.css || inlineCSS) {
|
||||
|
||||
@@ -41,39 +40,44 @@ ImportVisitor.prototype = {
|
||||
//if (importNode.isVariableImport()) {
|
||||
// console.log("variable import detected");
|
||||
//}
|
||||
var currentContext = this.context;
|
||||
|
||||
try {
|
||||
evaldImportNode = importNode.evalForImport(currentContext);
|
||||
} catch(e){
|
||||
if (!e.filename) { e.index = importNode.index; e.filename = importNode.currentFileInfo.filename; }
|
||||
// attempt to eval properly and treat as css
|
||||
importNode.css = true;
|
||||
// if that fails, this error will be thrown
|
||||
importNode.error = e;
|
||||
}
|
||||
|
||||
if (evaldImportNode && (!evaldImportNode.css || inlineCSS)) {
|
||||
importNode = evaldImportNode;
|
||||
this.importCount++;
|
||||
var context = new contexts.Eval(currentContext, currentContext.frames.slice(0));
|
||||
|
||||
if (importNode.options.multiple) {
|
||||
context.importMultiple = true;
|
||||
}
|
||||
|
||||
// try appending if we haven't determined if it is css or not
|
||||
var tryAppendLessExtension = importNode.css === undefined;
|
||||
|
||||
var onImported = this.onImported.bind(this, importNode, context),
|
||||
sequencedOnImported = this._sequencer.addImport(onImported);
|
||||
|
||||
this._importer.push(importNode.getPath(), tryAppendLessExtension, importNode.currentFileInfo, importNode.options, sequencedOnImported);
|
||||
}
|
||||
importNode = this.processImportNode(importNode, this.context);
|
||||
}
|
||||
visitArgs.visitDeeper = false;
|
||||
return importNode;
|
||||
},
|
||||
processImportNode: function(importNode, currentContext) {
|
||||
var evaldImportNode,
|
||||
inlineCSS = importNode.options.inline;
|
||||
|
||||
try {
|
||||
evaldImportNode = importNode.evalForImport(currentContext);
|
||||
} catch(e){
|
||||
if (!e.filename) { e.index = importNode.index; e.filename = importNode.currentFileInfo.filename; }
|
||||
// attempt to eval properly and treat as css
|
||||
importNode.css = true;
|
||||
// if that fails, this error will be thrown
|
||||
importNode.error = e;
|
||||
}
|
||||
|
||||
if (evaldImportNode && (!evaldImportNode.css || inlineCSS)) {
|
||||
importNode = evaldImportNode;
|
||||
this.importCount++;
|
||||
var context = new contexts.Eval(currentContext, currentContext.frames.slice(0));
|
||||
|
||||
if (importNode.options.multiple) {
|
||||
context.importMultiple = true;
|
||||
}
|
||||
|
||||
// try appending if we haven't determined if it is css or not
|
||||
var tryAppendLessExtension = importNode.css === undefined;
|
||||
|
||||
var onImported = this.onImported.bind(this, importNode, context),
|
||||
sequencedOnImported = this._sequencer.addImport(onImported);
|
||||
|
||||
this._importer.push(importNode.getPath(), tryAppendLessExtension, importNode.currentFileInfo, importNode.options, sequencedOnImported);
|
||||
}
|
||||
return importNode;
|
||||
},
|
||||
onImported: function (importNode, context, e, root, importedAtRoot, fullPath) {
|
||||
if (e && !e.filename) {
|
||||
e.index = importNode.index; e.filename = importNode.currentFileInfo.filename;
|
||||
|
||||
Reference in New Issue
Block a user