[Pkg-javascript-commits] [less.js] 16/285: remove the old importer interface and move the node code into the common importer

Jonas Smedegaard dr at jones.dk
Mon Oct 26 23:23:33 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 e989b01f514e5e2cc364c247ac938f1f817d28c3
Author: Luke Page <luke.a.page at gmail.com>
Date:   Sat Feb 22 16:47:59 2014 +0000

    remove the old importer interface and move the node code into the common importer
---
 lib/less/index.js  | 40 ++--------------------------------
 lib/less/parser.js | 63 ++++++++++++++++++++++++++++++++++++------------------
 2 files changed, 44 insertions(+), 59 deletions(-)

diff --git a/lib/less/index.js b/lib/less/index.js
index 7a9bbaa..d156090 100644
--- a/lib/less/index.js
+++ b/lib/less/index.js
@@ -87,6 +87,8 @@ var less = {
     }
 };
 
+less.Parser.environment = require("./environments/node");
+
 require('./tree/color');
 require('./tree/directive');
 require('./tree/detached-ruleset');
@@ -117,44 +119,6 @@ require('./tree/unicode-descriptor');
 require('./tree/negative');
 require('./tree/extend');
 require('./tree/ruleset-call');
-
-less.Parser.environment = require("./environments/node");
-
-less.Parser.fileLoader = function (filename, currentFileInfo, callback, env) {
-    var newFileInfo = {
-            relativeUrls: env.relativeUrls,
-            entryPath: currentFileInfo.entryPath,
-            rootpath: currentFileInfo.rootpath,
-            rootFilename: currentFileInfo.rootFilename
-        };
-        
-    function handleDataAndCallCallback(e, data, resolvedFilename) {
-        if (e) {
-            callback(e);
-            return;
-        }
-
-        // Pass on an updated rootpath if path of imported file is relative and file 
-        // is in a (sub|sup) directory
-        // 
-        // Examples: 
-        // - If path of imported file is 'module/nav/nav.less' and rootpath is 'less/',
-        //   then rootpath should become 'less/module/nav/'
-        // - If path of imported file is '../mixins.less' and rootpath is 'less/', 
-        //   then rootpath should become 'less/../'
-        var originalRelativePath = less.Parser.environment.getPath(env, filename);
-        if(newFileInfo.relativeUrls && !less.Parser.environment.isPathAbsolute(env, filename) && originalRelativePath) {
-            newFileInfo.rootpath = newFileInfo.rootpath + originalRelativePath; // append (sub|sup) directory path of imported file
-        }
-        newFileInfo.currentDirectory = less.Parser.environment.getPath(env, resolvedFilename);
-        newFileInfo.filename = resolvedFilename;
-
-        callback(null, data, resolvedFilename, newFileInfo); //TODO adjust callback
-    }
-
-    less.Parser.environment.loadFile(env, filename, currentFileInfo.currentDirectory, handleDataAndCallCallback);
-};
-
 require('./env');
 require('./functions');
 require('./colors');
diff --git a/lib/less/parser.js b/lib/less/parser.js
index 94d8858..40e3592 100644
--- a/lib/less/parser.js
+++ b/lib/less/parser.js
@@ -82,31 +82,52 @@ less.Parser = function Parser(env) {
                 callback(e, root, importedPreviously, fullPath);
             };
 
-            if (less.Parser.importer) {
-                less.Parser.importer(path, currentFileInfo, fileParsedFunc, env);
-            } else {
-                less.Parser.fileLoader(path, currentFileInfo, function(e, contents, fullPath, newFileInfo) {
-                    if (e) {fileParsedFunc(e); return;}
+            var newFileInfo = {
+                relativeUrls: env.relativeUrls,
+                entryPath: currentFileInfo.entryPath,
+                rootpath: currentFileInfo.rootpath,
+                rootFilename: currentFileInfo.rootFilename
+                };
+            
+            less.Parser.environment.loadFile(env, path, currentFileInfo.currentDirectory, function (e, contents, resolvedFilename) {
+                if (e) {
+                    fileParsedFunc(e);
+                    return;
+                }
 
-                    var newEnv = new tree.parseEnv(env);
+                // Pass on an updated rootpath if path of imported file is relative and file 
+                // is in a (sub|sup) directory
+                // 
+                // Examples: 
+                // - If path of imported file is 'module/nav/nav.less' and rootpath is 'less/',
+                //   then rootpath should become 'less/module/nav/'
+                // - If path of imported file is '../mixins.less' and rootpath is 'less/', 
+                //   then rootpath should become 'less/../'
+                var originalRelativePath = less.Parser.environment.getPath(env, path);
+                if(newFileInfo.relativeUrls && !less.Parser.environment.isPathAbsolute(env, path) && originalRelativePath) {
+                    newFileInfo.rootpath = newFileInfo.rootpath + originalRelativePath; // append (sub|sup) directory path of imported file
+                }
+                newFileInfo.currentDirectory = less.Parser.environment.getPath(env, resolvedFilename);
+                newFileInfo.filename = resolvedFilename;
 
-                    newEnv.currentFileInfo = newFileInfo;
-                    newEnv.processImports = false;
-                    newEnv.contents[fullPath] = contents;
+                var newEnv = new tree.parseEnv(env);
 
-                    if (currentFileInfo.reference || importOptions.reference) {
-                        newFileInfo.reference = true;
-                    }
+                newEnv.currentFileInfo = newFileInfo;
+                newEnv.processImports = false;
+                newEnv.contents[resolvedFilename] = contents;
 
-                    if (importOptions.inline) {
-                        fileParsedFunc(null, contents, fullPath);
-                    } else {
-                        new(less.Parser)(newEnv).parse(contents, function (e, root) {
-                            fileParsedFunc(e, root, fullPath);
-                        });
-                    }
-                }, env);
-            }
+                if (currentFileInfo.reference || importOptions.reference) {
+                    newFileInfo.reference = true;
+                }
+
+                if (importOptions.inline) {
+                    fileParsedFunc(null, contents, resolvedFilename);
+                } else {
+                    new(less.Parser)(newEnv).parse(contents, function (e, root) {
+                        fileParsedFunc(e, root, resolvedFilename);
+                    });
+                }                    
+            });
         }
     };
 

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