[Pkg-javascript-commits] [less.js] 229/285: Tidy context stack into actual stack - no need for an array

Jonas Smedegaard dr at jones.dk
Mon Oct 26 23:23:57 UTC 2015


This is an automated email from the git hooks/post-receive script.

js pushed a commit to annotated tag v2.0.0
in repository less.js.

commit 59310251b6207aa178b71df48686fb066a991b46
Author: Luke Page <luke.a.page at gmail.com>
Date:   Thu Oct 23 21:50:01 2014 +0100

    Tidy context stack into actual stack - no need for an array
---
 lib/less/visitors/import-visitor.js | 34 +++++++++++++---------------------
 1 file changed, 13 insertions(+), 21 deletions(-)

diff --git a/lib/less/visitors/import-visitor.js b/lib/less/visitors/import-visitor.js
index 255ac72..9261f7b 100644
--- a/lib/less/visitors/import-visitor.js
+++ b/lib/less/visitors/import-visitor.js
@@ -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;

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-javascript/less.js.git



More information about the Pkg-javascript-commits mailing list