[Pkg-javascript-commits] [less.js] 82/88: always execute import-once in the same way. Fixes #1898

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


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

js pushed a commit to annotated tag v1.7.0
in repository less.js.

commit ccd8ebbfdfa300b6e748e8d7c12e3dbb0efd8371
Author: Luke Page <luke.a.page at gmail.com>
Date:   Thu Feb 27 06:12:31 2014 +0000

    always execute import-once in the same way. Fixes #1898
---
 lib/less/import-visitor.js | 34 +++++++++++++++++++++++++++++-----
 lib/less/parser.js         |  2 +-
 lib/less/tree/import.js    |  9 ++++++++-
 3 files changed, 38 insertions(+), 7 deletions(-)

diff --git a/lib/less/import-visitor.js b/lib/less/import-visitor.js
index 0d773ca..7d69337 100644
--- a/lib/less/import-visitor.js
+++ b/lib/less/import-visitor.js
@@ -1,10 +1,19 @@
 (function (tree) {
-    tree.importVisitor = function(importer, finish, evalEnv) {
+    tree.importVisitor = function(importer, finish, evalEnv, onceFileDetectionMap, recursionDetector) {
         this._visitor = new tree.visitor(this);
         this._importer = importer;
         this._finish = finish;
         this.env = evalEnv || new tree.evalEnv();
         this.importCount = 0;
+        this.onceFileDetectionMap = onceFileDetectionMap || {};
+        this.recursionDetector = {};
+        if (recursionDetector) {
+            for(var fullFilename in recursionDetector) {
+                if (recursionDetector.hasOwnProperty(fullFilename)) {
+                    this.recursionDetector[fullFilename] = true;
+                }
+            }
+        }
     };
 
     tree.importVisitor.prototype = {
@@ -51,10 +60,22 @@
                         env.importMultiple = true;
                     }
 
-                    this._importer.push(importNode.getPath(), importNode.currentFileInfo, importNode.options, function (e, root, imported, fullPath) {
+                    this._importer.push(importNode.getPath(), importNode.currentFileInfo, importNode.options, function (e, root, importedAtRoot, fullPath) {
                         if (e && !e.filename) { e.index = importNode.index; e.filename = importNode.currentFileInfo.filename; }
 
-                        if (imported && !env.importMultiple) { importNode.skip = imported; }
+                        if (!env.importMultiple) { 
+                            if (importedAtRoot) {
+                                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--;
@@ -67,8 +88,11 @@
                         if (root) {
                             importNode.root = root;
                             importNode.importedFilename = fullPath;
-                            if (!inlineCSS && !importNode.skip) {
-                                new(tree.importVisitor)(importVisitor._importer, subFinish, env)
+                            var duplicateImport = importedAtRoot || fullPath in importVisitor.recursionDetector;
+
+                            if (!inlineCSS && (env.importMultiple || !duplicateImport)) {
+                                importVisitor.recursionDetector[fullPath] = true;
+                                new(tree.importVisitor)(importVisitor._importer, subFinish, env, importVisitor.onceFileDetectionMap, importVisitor.recursionDetector)
                                     .run(root);
                                 return;
                             }
diff --git a/lib/less/parser.js b/lib/less/parser.js
index 74f2ddd..91457ac 100644
--- a/lib/less/parser.js
+++ b/lib/less/parser.js
@@ -73,7 +73,7 @@ less.Parser = function Parser(env) {
             var fileParsedFunc = function (e, root, fullPath) {
                 parserImports.queue.splice(parserImports.queue.indexOf(path), 1); // Remove the path from the queue
 
-                var importedPreviously = fullPath in parserImports.files || fullPath === rootFilename;
+                var importedPreviously = fullPath === rootFilename;
 
                 parserImports.files[fullPath] = root;                        // Store the root
 
diff --git a/lib/less/tree/import.js b/lib/less/tree/import.js
index 910fc11..7042f04 100644
--- a/lib/less/tree/import.js
+++ b/lib/less/tree/import.js
@@ -92,7 +92,14 @@ tree.Import.prototype = {
     eval: function (env) {
         var ruleset, features = this.features && this.features.eval(env);
 
-        if (this.skip) { return []; }
+        if (this.skip) {
+            if (typeof this.skip === "function") {
+                this.skip = this.skip();
+            }
+            if (this.skip) {
+                return []; 
+            }
+        }
          
         if (this.options.inline) {
             //todo needs to reference css file not import

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