mirror of
https://github.com/less/less.js.git
synced 2026-04-09 03:00:20 -04:00
Tidy context stack into actual stack - no need for an array
This commit is contained in:
@@ -7,8 +7,7 @@ var ImportVisitor = function(importer, finish) {
|
||||
this._visitor = new Visitor(this);
|
||||
this._importer = importer;
|
||||
this._finish = finish;
|
||||
// TODO probably doesnt need to be an array
|
||||
this.contextStack = [new contexts.Eval()];
|
||||
this.context = new contexts.Eval();
|
||||
this.importCount = 0;
|
||||
this.onceFileDetectionMap = {};
|
||||
this.recursionDetector = {};
|
||||
@@ -42,7 +41,7 @@ ImportVisitor.prototype = {
|
||||
//if (importNode.isVariableImport()) {
|
||||
// console.log("variable import detected");
|
||||
//}
|
||||
var currentContext = this.contextStack[this.contextStack.length - 1];
|
||||
var currentContext = this.context;
|
||||
|
||||
try {
|
||||
evaldImportNode = importNode.evalForImport(currentContext);
|
||||
@@ -115,13 +114,14 @@ ImportVisitor.prototype = {
|
||||
if (!inlineCSS && (context.importMultiple || !duplicateImport)) {
|
||||
importVisitor.recursionDetector[fullPath] = true;
|
||||
|
||||
this.contextStack.push(context);
|
||||
var oldContext = this.context;
|
||||
this.context = context;
|
||||
try {
|
||||
this._visitor.visit(root);
|
||||
} catch (e) {
|
||||
this.error = e;
|
||||
}
|
||||
this.contextStack.pop();
|
||||
this.context = oldContext;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -132,40 +132,32 @@ ImportVisitor.prototype = {
|
||||
return ruleNode;
|
||||
},
|
||||
visitDirective: function (directiveNode, visitArgs) {
|
||||
var currentContext = this.contextStack[this.contextStack.length - 1];
|
||||
currentContext.frames.unshift(directiveNode);
|
||||
this.context.frames.unshift(directiveNode);
|
||||
return directiveNode;
|
||||
},
|
||||
visitDirectiveOut: function (directiveNode) {
|
||||
var currentContext = this.contextStack[this.contextStack.length - 1];
|
||||
currentContext.frames.shift();
|
||||
this.context.frames.shift();
|
||||
},
|
||||
visitMixinDefinition: function (mixinDefinitionNode, visitArgs) {
|
||||
var currentContext = this.contextStack[this.contextStack.length - 1];
|
||||
currentContext.frames.unshift(mixinDefinitionNode);
|
||||
this.context.frames.unshift(mixinDefinitionNode);
|
||||
return mixinDefinitionNode;
|
||||
},
|
||||
visitMixinDefinitionOut: function (mixinDefinitionNode) {
|
||||
var currentContext = this.contextStack[this.contextStack.length - 1];
|
||||
currentContext.frames.shift();
|
||||
this.context.frames.shift();
|
||||
},
|
||||
visitRuleset: function (rulesetNode, visitArgs) {
|
||||
var currentContext = this.contextStack[this.contextStack.length - 1];
|
||||
currentContext.frames.unshift(rulesetNode);
|
||||
this.context.frames.unshift(rulesetNode);
|
||||
return rulesetNode;
|
||||
},
|
||||
visitRulesetOut: function (rulesetNode) {
|
||||
var currentContext = this.contextStack[this.contextStack.length - 1];
|
||||
currentContext.frames.shift();
|
||||
this.context.frames.shift();
|
||||
},
|
||||
visitMedia: function (mediaNode, visitArgs) {
|
||||
var currentContext = this.contextStack[this.contextStack.length - 1];
|
||||
currentContext.frames.unshift(mediaNode.rules[0]);
|
||||
this.context.frames.unshift(mediaNode.rules[0]);
|
||||
return mediaNode;
|
||||
},
|
||||
visitMediaOut: function (mediaNode) {
|
||||
var currentContext = this.contextStack[this.contextStack.length - 1];
|
||||
currentContext.frames.shift();
|
||||
this.context.frames.shift();
|
||||
}
|
||||
};
|
||||
module.exports = ImportVisitor;
|
||||
|
||||
Reference in New Issue
Block a user