[Pkg-javascript-commits] [less.js] 224/285: Sequencer working so imports are always processed in the same order

Jonas Smedegaard dr at jones.dk
Mon Oct 26 23:23:56 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 e793b17751a7217654cd3abe980bf267bb550613
Author: Luke Page <luke.a.page at gmail.com>
Date:   Thu Oct 23 18:15:25 2014 +0100

    Sequencer working so imports are always processed in the same order
---
 lib/less/visitors/import-sequencer.js |   4 +-
 lib/less/visitors/import-visitor.js   | 101 ++++++++++++++++++----------------
 2 files changed, 55 insertions(+), 50 deletions(-)

diff --git a/lib/less/visitors/import-sequencer.js b/lib/less/visitors/import-sequencer.js
index e87f26d..6fb4639 100644
--- a/lib/less/visitors/import-sequencer.js
+++ b/lib/less/visitors/import-sequencer.js
@@ -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;
\ No newline at end of file
+module.exports = ImportSequencer;
diff --git a/lib/less/visitors/import-visitor.js b/lib/less/visitors/import-visitor.js
index 2da7c55..d719cb2 100644
--- a/lib/less/visitors/import-visitor.js
+++ b/lib/less/visitors/import-visitor.js
@@ -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,52 +64,60 @@ 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 subFinish = function(e) {
-                        importVisitor.importCount--;
+                var onImported = this.onImported.bind(this, importNode, context),
+                    sequencedOnImported = this._sequencer.addImport(onImported);
 
-                        if (importVisitor.importCount === 0 && importVisitor.isFinished) {
-                            importVisitor._finish(e);
-                        }
-                    };
+                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;
+        }
 
-                    if (root) {
-                        importNode.root = root;
-                        importNode.importedFilename = fullPath;
+        var importVisitor = this,
+            inlineCSS = importNode.options.inline,
+            duplicateImport = importedAtRoot || fullPath in importVisitor.recursionDetector;
 
-                        if (!inlineCSS && (context.importMultiple || !duplicateImport)) {
-                            importVisitor.recursionDetector[fullPath] = true;
-                            new ImportVisitor(importVisitor._importer, subFinish, context, importVisitor.onceFileDetectionMap, importVisitor.recursionDetector)
-                                .run(root);
-                            return;
-                        }
+        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--;
 
-                    subFinish();
-                });
+            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;
             }
         }
-        visitArgs.visitDeeper = false;
-        return importNode;
+
+        subFinish();
     },
     visitRule: function (ruleNode, visitArgs) {
         visitArgs.visitDeeper = false;

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