remove env from all environment calls except the ones that actually need it

This commit is contained in:
Luke Page
2014-09-21 16:46:44 +01:00
parent a53be80014
commit fb6c879cc4
9 changed files with 43 additions and 43 deletions

View File

@@ -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() {
}
};

View File

@@ -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'; }
}

View File

@@ -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;
}

View File

@@ -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);
}
}

View File

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

View File

@@ -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) {