[Pkg-javascript-commits] [less.js] 230/285: Refactor out the processing of the import, ready to be done asyncronously

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 59a165ba332c62b7bbb4493db545ccd5540fd058
Author: Luke Page <luke.a.page at gmail.com>
Date:   Thu Oct 23 22:02:48 2014 +0100

    Refactor out the processing of the import, ready to be done asyncronously
---
 lib/less/visitors/import-visitor.js | 58 ++++++++++++++++++++-----------------
 1 file changed, 31 insertions(+), 27 deletions(-)

diff --git a/lib/less/visitors/import-visitor.js b/lib/less/visitors/import-visitor.js
index 9261f7b..6a8f3d2 100644
--- a/lib/less/visitors/import-visitor.js
+++ b/lib/less/visitors/import-visitor.js
@@ -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,37 +40,42 @@ 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;
-            }
+            importNode = this.processImportNode(importNode, this.context);
+        }
+        visitArgs.visitDeeper = false;
+        return importNode;
+    },
+    processImportNode: function(importNode, currentContext) {
+        var evaldImportNode,
+            inlineCSS = importNode.options.inline;
 
-            if (evaldImportNode && (!evaldImportNode.css || inlineCSS)) {
-                importNode = evaldImportNode;
-                this.importCount++;
-                var context = new contexts.Eval(currentContext, currentContext.frames.slice(0));
+        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 (importNode.options.multiple) {
-                    context.importMultiple = true;
-                }
+        if (evaldImportNode && (!evaldImportNode.css || inlineCSS)) {
+            importNode = evaldImportNode;
+            this.importCount++;
+            var context = new contexts.Eval(currentContext, currentContext.frames.slice(0));
 
-                // try appending if we haven't determined if it is css or not
-                var tryAppendLessExtension = importNode.css === undefined;
+            if (importNode.options.multiple) {
+                context.importMultiple = true;
+            }
 
-                var onImported = this.onImported.bind(this, importNode, context),
-                    sequencedOnImported = this._sequencer.addImport(onImported);
+            // 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, sequencedOnImported);
-            }
+            var onImported = this.onImported.bind(this, importNode, context),
+                sequencedOnImported = this._sequencer.addImport(onImported);
+
+            this._importer.push(importNode.getPath(), tryAppendLessExtension, importNode.currentFileInfo, importNode.options, sequencedOnImported);
         }
-        visitArgs.visitDeeper = false;
         return importNode;
     },
     onImported: function (importNode, context, e, root, importedAtRoot, fullPath) {

-- 
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