[Pkg-javascript-commits] [less.js] 222/285: Initial sketch-out (broken)

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 8c89b268b386d095692ebb8ec486dd6de9171f0d
Author: Luke Page <luke.a.page at gmail.com>
Date:   Thu Oct 23 13:00:20 2014 +0100

    Initial sketch-out (broken)
---
 lib/less/visitors/import-sequencer.js | 35 +++++++++++++++++++++++++++++++++++
 lib/less/visitors/import-visitor.js   | 17 ++++++++++-------
 2 files changed, 45 insertions(+), 7 deletions(-)

diff --git a/lib/less/visitors/import-sequencer.js b/lib/less/visitors/import-sequencer.js
new file mode 100644
index 0000000..e87f26d
--- /dev/null
+++ b/lib/less/visitors/import-sequencer.js
@@ -0,0 +1,35 @@
+function ImportSequencer(onSequencerEmpty) {
+    this.imports = [];
+    this._onSequencerEmpty = onSequencerEmpty;
+}
+
+ImportSequencer.prototype.addImport = function(callback) {
+    var importSequencer = this,
+        importItem = {
+            callback: callback,
+            args: null,
+            isReady: false
+        };
+    this.imports.push(importItem);
+    return function() {
+        importItem.args = [].concat(arguments);
+        importItem.isReady = true;
+        importSequencer.tryRun();
+    };
+};
+
+ImportSequencer.prototype.tryRun = function() {
+    while(this.imports.length > 0) {
+        var importItem = this.imports[0];
+        if (!importItem.isReady) {
+            return;
+        }
+        this.imports = this.imports.slice(1);
+        importItem.callback.apply(null, importItem.args);
+    }
+    if (this._onSequencerEmpty) {
+        this._onSequencerEmpty();
+    }
+};
+
+module.exports = ImportSequencer;
\ No newline at end of file
diff --git a/lib/less/visitors/import-visitor.js b/lib/less/visitors/import-visitor.js
index e995c7c..2da7c55 100644
--- a/lib/less/visitors/import-visitor.js
+++ b/lib/less/visitors/import-visitor.js
@@ -1,5 +1,6 @@
 var contexts = require("../contexts"),
-    Visitor = require("./visitor");
+    Visitor = require("./visitor"),
+    ImportSequencer = require("./import-sequencer");
 
 var ImportVisitor = function(importer, finish, evalEnv, onceFileDetectionMap, recursionDetector) {
     this._visitor = new Visitor(this);
@@ -16,25 +17,27 @@ var ImportVisitor = function(importer, finish, evalEnv, onceFileDetectionMap, re
             }
         }
     }
+    this._sequencer = new ImportSequencer(this._onSequencerEmpty.bind(this));
 };
 
 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) {
-            error = e;
+            this.error = e;
         }
 
         this.isFinished = true;
-
-        if (this.importCount === 0) {
-            this._finish(error);
-        }
+        this._sequencer.tryRun();
     },
     visitImport: function (importNode, visitArgs) {
         var importVisitor = this,

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