[Pkg-javascript-commits] [less.js] 133/285: remove env from all environment calls except the ones that actually need it

Jonas Smedegaard dr at jones.dk
Mon Oct 26 23:23:47 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 fb6c879cc493e41ba91027eb91dfd2600163479c
Author: Luke Page <luke.a.page at gmail.com>
Date:   Sun Sep 21 16:46:44 2014 +0100

    remove env from all environment calls except the ones that actually need it
---
 lib/less-browser/environment.js | 16 +++++++++-------
 lib/less-browser/index.js       |  4 ++--
 lib/less-node/environment.js    | 28 +++++++++++++++-------------
 lib/less/environment/api.js     | 15 ++++++---------
 lib/less/functions/data-uri.js  |  6 +++---
 lib/less/functions/svg.js       |  2 +-
 lib/less/imports.js             | 11 +++++------
 lib/less/parser/parser.js       |  2 +-
 lib/less/source-map-output.js   |  2 +-
 9 files changed, 43 insertions(+), 43 deletions(-)

diff --git a/lib/less-browser/environment.js b/lib/less-browser/environment.js
index 2e045c7..5f65bd4 100644
--- a/lib/less-browser/environment.js
+++ b/lib/less-browser/environment.js
@@ -23,11 +23,11 @@ function getXMLHttpRequest() {
 
 return {
     // make generic but overriddable
-    warn: function warn(env, msg) {
+    warn: function warn(msg) {
         console.warn(msg);
     },
     // make generic but overriddable
-    getPath: function getPath(env, filename) {
+    getPath: function getPath(filename) {
         var j = filename.lastIndexOf('/');
         if (j < 0) {
             j = filename.lastIndexOf('\\');
@@ -38,7 +38,7 @@ return {
         return filename.slice(0, j + 1);
     },
     // make generic but overriddable
-    isPathAbsolute: function isPathAbsolute(env, filename) {
+    isPathAbsolute: function isPathAbsolute(filename) {
         return /^(?:[a-z-]+:|\/|\\)/i.test(filename);
     },
     alwaysMakePathsAbsolute: function alwaysMakePathsAbsolute() {
@@ -168,17 +168,19 @@ return {
             handleResponse(xhr, callback, errback);
         }
     },
-    loadFile: function loadFile(env, filename, currentDirectory, callback) {
-        if (currentDirectory && !this.isPathAbsolute(env, filename)) {
+    loadFile: function loadFile(filename, currentDirectory, options, callback) {
+        if (currentDirectory && !this.isPathAbsolute(filename)) {
             filename = currentDirectory + filename;
         }
 
+        options = options || {};
+
         // sheet may be set to the stylesheet for the initial load or a collection of properties including
         // some env variables for imports
         var hrefParts = this.extractUrlParts(filename, window.location.href);
         var href      = hrefParts.url;
 
-        if (env.useFileCache && fileCache[href]) {
+        if (options.useFileCache && fileCache[href]) {
             try {
                 var lessText = fileCache[href];
                 callback(null, lessText, href, { lastModified: new Date() });
@@ -188,7 +190,7 @@ return {
             return;
         }
 
-        this.doXHR(href, env.mime, function doXHRCallback(data, lastModified) {
+        this.doXHR(href, options.mime, function doXHRCallback(data, lastModified) {
             // per file cache
             fileCache[href] = data;
 
diff --git a/lib/less-browser/index.js b/lib/less-browser/index.js
index a767c60..36c4cb4 100644
--- a/lib/less-browser/index.js
+++ b/lib/less-browser/index.js
@@ -377,10 +377,10 @@ function loadStyleSheet(sheet, callback, reload, remaining, modifyVars) {
         instanceOptions.useFileCache = true;
     }
 
-    less.environment.loadFile(instanceOptions, sheet.href, null, function loadInitialFileCallback(e, data, path, webInfo) {
+    less.environment.loadFile(sheet.href, null, instanceOptions, function loadInitialFileCallback(e, data, path, webInfo) {
 
         var newFileInfo = {
-            currentDirectory: less.environment.getPath(instanceOptions, path),
+            currentDirectory: less.environment.getPath(path),
             filename: path,
             rootFilename: path,
             relativeUrls: instanceOptions.relativeUrls};
diff --git a/lib/less-node/environment.js b/lib/less-node/environment.js
index 3340091..c22a583 100644
--- a/lib/less-node/environment.js
+++ b/lib/less-node/environment.js
@@ -5,25 +5,25 @@ var path = require('path'),
     isUrlRe = /^(?:https?:)?\/\//i;
 
 module.exports = {
-    warn: function(env, msg) {
+    warn: function(msg) {
         console.warn(msg);
     },
-    encodeBase64: function encodeBase64(env, str) {
+    encodeBase64: function encodeBase64(str) {
         return new Buffer(str).toString('base64');
     },
-    supportsDataURI: function(env) {
+    supportsDataURI: function() {
         return true;
     },
-    mimeLookup: function (env, filename) {
+    mimeLookup: function (filename) {
         return require('mime').lookup(filename);
     },
-    charsetLookup: function (env, mime) {
+    charsetLookup: function (mime) {
         return require('mime').charsets.lookup(mime);
     },
     readFileSync: function (filename) {
         return require("fs").readFileSync(filename);
     },
-    getPath: function (env, filename) {
+    getPath: function (filename) {
         var j = filename.lastIndexOf('/');
         if (j < 0) {
             j = filename.lastIndexOf('\\');
@@ -33,10 +33,10 @@ module.exports = {
         }
         return filename.slice(0, j + 1);
     },
-    isPathAbsolute: function(env, filename) {
+    isPathAbsolute: function(filename) {
         return (/^(?:[a-z-]+:|\/|\\)/i).test(filename);
     },
-    getAbsolutePath: function getAbsolutePath(env, filename) {
+    getAbsolutePath: function getAbsolutePath(filename) {
         return require('path').resolve(filename);
     },
     getSourceMapGenerator: function getSourceMapGenerator() {
@@ -128,11 +128,13 @@ module.exports = {
         returner.url = returner.fileUrl + (urlParts[5] || "");
         return returner;
     },
-    loadFile: function(env, filename, currentDirectory, callback) {
+    loadFile: function(filename, currentDirectory, options, callback) {
         var fullFilename,
             data,
             isUrl = isUrlRe.test( filename );
 
+        options = options || {};
+
         if (isUrl || isUrlRe.test(currentDirectory)) {
             if (request === undefined) {
                 try { request = require('request'); }
@@ -151,7 +153,7 @@ module.exports = {
                 urlStr = urlObj.format();
             }
 
-            request.get({uri: urlStr, strictSSL: !env.insecure }, function (error, res, body) {
+            request.get({uri: urlStr, strictSSL: !options.insecure }, function (error, res, body) {
                 if (error) {
                     callback({ type: 'File', message: "resource '" + urlStr + "' gave this Error:\n  "+ error +"\n" });
                 }
@@ -160,7 +162,7 @@ module.exports = {
                     return;
                 }
                 if (!body) {
-                    this.warn( env, 'Warning: Empty body (HTTP '+ res.statusCode + ') returned by "' + urlStr +'"');
+                    this.warn('Warning: Empty body (HTTP '+ res.statusCode + ') returned by "' + urlStr +'"');
                 }
                 fullFilename = urlStr;
                 callback(null, body, fullFilename);
@@ -168,10 +170,10 @@ module.exports = {
         } else {
 
             var paths = [currentDirectory];
-            if (env.paths) paths.push.apply(paths, env.paths);
+            if (options.paths) paths.push.apply(paths, options.paths);
             if (paths.indexOf('.') === -1) paths.push('.');
 
-            if (env.syncImport) {
+            if (options.syncImport) {
                 for (var i = 0; i < paths.length; i++) {
                     try {
                         fullFilename = path.join(paths[i], filename);
diff --git a/lib/less/environment/api.js b/lib/less/environment/api.js
index ef3dee2..90a71fc 100644
--- a/lib/less/environment/api.js
+++ b/lib/less/environment/api.js
@@ -1,42 +1,39 @@
 module.exports = {
     /**
       * Warns the user about something
-      * @param {Object} env - the environment or options object
       * @param {String} msg - the message about the warning
       */
-    warn: function(env, msg) {
+    warn: function(msg) {
     },
     /**
       * gets the path from the filename, e.g. "http://wwe.files.com/ha/ha.less" would return
       * "http://wwe.files.com/ha/"
       * If the filename is a file e.g. "file.less" it should return the empty string ""
-      * @param {Object} env - the environment or options object
       * @param {String} filename - the filename to extract the path.
       * @returns {String}
       */
-    getPath: function (env, filename) {
+    getPath: function (filename) {
     },
     /**
       * Returns whether the path is absolute, e.g. "/file.less" = true, "file.less" = false
-      * @param {Object} env - the environment or options object
       * @param {String} filename - the filename
       * @returns {Boolean}
       */
-    isPathAbsolute: function(env, filename) {
+    isPathAbsolute: function(filename) {
     },
     /**
       * Loads a file for an import aynscronously (or syncronously)
-      * @param {Object} env - the environment or options object
       * @param {String} filename - the filename
       * @param {String} currentDirectory - the current directory we are in
+      * @param {Object} options - the environment or options object
       * @param {Function} callback - a function to callback when finished,
       *                   taking the format callback(error, contents, fullfilename, reserved)
       *                   where error is { type: {string}, message: {string} }, contents is {string} and fullfilename is {string}
       *                   for reserved, see less-browser/index.js which uses this argument for cache information
       * @returns {Boolean}
       */
-    loadFile: function(env, filename, currentDirectory, callback) {
+    loadFile: function(filename, currentDirectory, options, callback) {
     },
-    supportsDataURI: function(env) {
+    supportsDataURI: function() {
     }
 };
diff --git a/lib/less/functions/data-uri.js b/lib/less/functions/data-uri.js
index 3112d80..8a4ee5e 100644
--- a/lib/less/functions/data-uri.js
+++ b/lib/less/functions/data-uri.js
@@ -5,7 +5,7 @@ module.exports = function(environment) {
 
     functionRegistry.add("data-uri", function(mimetypeNode, filePathNode) {
 
-        if (!environment.supportsDataURI(this.env)) {
+        if (!environment.supportsDataURI()) {
             return new URL(filePathNode || mimetypeNode, this.index, this.currentFileInfo).eval(this.env);
         }
 
@@ -36,10 +36,10 @@ module.exports = function(environment) {
         // detect the mimetype if not given
         if (arguments.length < 2) {
 
-            mimetype = environment.mimeLookup(this.env, filePath);
+            mimetype = environment.mimeLookup(filePath);
 
             // use base 64 unless it's an ASCII or UTF-8 format
-            var charset = environment.charsetLookup(this.env, mimetype);
+            var charset = environment.charsetLookup(mimetype);
             useBase64 = ['US-ASCII', 'UTF-8'].indexOf(charset) < 0;
             if (useBase64) { mimetype += ';base64'; }
         }
diff --git a/lib/less/functions/svg.js b/lib/less/functions/svg.js
index 5bd8fc6..ba80302 100644
--- a/lib/less/functions/svg.js
+++ b/lib/less/functions/svg.js
@@ -71,7 +71,7 @@ module.exports = function(environment) {
 
         if (useBase64) {
             try {
-                returner = environment.encodeBase64(this.env, returner);
+                returner = environment.encodeBase64(returner);
             } catch(e) {
                 useBase64 = false;
             }
diff --git a/lib/less/imports.js b/lib/less/imports.js
index a5fcdd4..bcd5a6c 100644
--- a/lib/less/imports.js
+++ b/lib/less/imports.js
@@ -1,7 +1,6 @@
 var contexts = require("./contexts"),
     Parser = require('./parser/parser');
 
-// TODO - why does environment need env passed everywhere?
 // Now we have one import manager per parse, can we move things from env to the import manager
 // and then move the import manager onto env (if required there - if not, keep seperate)
 
@@ -17,10 +16,10 @@ module.exports = function(environment) {
         this.error = null;
         this.env = env;
     };
-    ImportManager.prototype.getAbsolutePath = function(env, filename) {
+    ImportManager.prototype.getAbsolutePath = function(filename) {
         // proxy needed for "DebugInfo"
         // I hope one day we can remove this function
-        return environment.getAbsolutePath(env, filename);
+        return environment.getAbsolutePath(filename);
     };
     ImportManager.prototype.push = function (path, currentFileInfo, importOptions, callback) {
         var parserImports = this;
@@ -45,7 +44,7 @@ module.exports = function(environment) {
             rootFilename: currentFileInfo.rootFilename
         };
 
-        environment.loadFile(this.env, path, currentFileInfo.currentDirectory, function loadFileCallback(e, contents, resolvedFilename) {
+        environment.loadFile(path, currentFileInfo.currentDirectory, this.env, function loadFileCallback(e, contents, resolvedFilename) {
             if (e) {
                 fileParsedFunc(e);
                 return;
@@ -59,10 +58,10 @@ module.exports = function(environment) {
             //   then rootpath should become 'less/module/nav/'
             // - If path of imported file is '../mixins.less' and rootpath is 'less/',
             //   then rootpath should become 'less/../'
-            newFileInfo.currentDirectory = environment.getPath(parserImports.env, resolvedFilename);
+            newFileInfo.currentDirectory = environment.getPath(resolvedFilename);
             if(newFileInfo.relativeUrls) {
                 newFileInfo.rootpath = environment.join((parserImports.env.rootpath || ""), environment.pathDiff(newFileInfo.currentDirectory, newFileInfo.entryPath));
-                if (!environment.isPathAbsolute(parserImports.env, newFileInfo.rootpath) && environment.alwaysMakePathsAbsolute()) {
+                if (!environment.isPathAbsolute(newFileInfo.rootpath) && environment.alwaysMakePathsAbsolute()) {
                     newFileInfo.rootpath = environment.join(newFileInfo.entryPath, newFileInfo.rootpath);
                 }
             }
diff --git a/lib/less/parser/parser.js b/lib/less/parser/parser.js
index d623223..5632e9d 100644
--- a/lib/less/parser/parser.js
+++ b/lib/less/parser/parser.js
@@ -73,7 +73,7 @@ var Parser = function Parser(env, imports) {
 
     function getDebugInfo(index) {
         var filename = env.currentFileInfo.filename;
-        filename = imports.getAbsolutePath(env, filename);
+        filename = imports.getAbsolutePath(filename);
 
         return {
             lineNumber: utils.getLocation(index, parserInput.getInput()).line + 1,
diff --git a/lib/less/source-map-output.js b/lib/less/source-map-output.js
index c8fd807..5f4c9de 100644
--- a/lib/less/source-map-output.js
+++ b/lib/less/source-map-output.js
@@ -128,7 +128,7 @@ module.exports = function (environment) {
             if (!this._sourceMapFileInline) {
                 this.sourceMap = sourceMapContent;
             } else {
-                sourceMapURL = "data:application/json;base64," + environment.encodeBase64(null, sourceMapContent);
+                sourceMapURL = "data:application/json;base64," + environment.encodeBase64(sourceMapContent);
             }
 
             if (sourceMapURL) {

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