mirror of
https://github.com/less/less.js.git
synced 2026-05-01 03:00:22 -04:00
Fix tests
This commit is contained in:
@@ -349,7 +349,7 @@ function loadStyleSheet(sheet, callback, reload, remaining, modifyVars) {
|
||||
relativeUrls: env.relativeUrls};
|
||||
|
||||
newFileInfo.entryPath = newFileInfo.currentDirectory;
|
||||
newFileInfo.rootpath = less.rootpath || newFileInfo.currentDirectory;
|
||||
newFileInfo.rootpath = env.rootpath || newFileInfo.currentDirectory;
|
||||
|
||||
if (webInfo) {
|
||||
webInfo.remaining = remaining;
|
||||
|
||||
@@ -6,12 +6,12 @@ var fileCache = {};
|
||||
// isFileProtocol is global
|
||||
|
||||
function getXMLHttpRequest() {
|
||||
if (window.XMLHttpRequest) {
|
||||
if (window.XMLHttpRequest && (window.location.protocol !== "file:" || !window.ActiveXObject)) {
|
||||
return new XMLHttpRequest();
|
||||
} else {
|
||||
try {
|
||||
/*global ActiveXObject */
|
||||
return new ActiveXObject("MSXML2.XMLHTTP.3.0");
|
||||
return new ActiveXObject("Microsoft.XMLHTTP");
|
||||
} catch (e) {
|
||||
log("browser doesn't support AJAX.", logLevel.errors);
|
||||
return null;
|
||||
@@ -39,6 +39,9 @@ less.Parser.environment = {
|
||||
isPathAbsolute: function isPathAbsolute(env, filename) {
|
||||
return /^(?:[a-z-]+:|\/|\\)/.test(filename);
|
||||
},
|
||||
alwaysMakePathsAbsolute: function alwaysMakePathsAbsolute() {
|
||||
return true;
|
||||
},
|
||||
pathDiff: function pathDiff(url, baseUrl) {
|
||||
// diff between two paths to create a relative path
|
||||
|
||||
@@ -62,6 +65,12 @@ less.Parser.environment = {
|
||||
}
|
||||
return diff;
|
||||
},
|
||||
join: function join(basePath, laterPath) {
|
||||
if (!basePath) {
|
||||
return laterPath;
|
||||
}
|
||||
return this.extractUrlParts(laterPath, basePath).path;
|
||||
},
|
||||
// helper function, not part of API
|
||||
extractUrlParts: function extractUrlParts(url, baseUrl) {
|
||||
// urlParts[1] = protocol&hostname || /
|
||||
|
||||
@@ -19,7 +19,93 @@ module.exports = {
|
||||
return filename.slice(0, j + 1);
|
||||
},
|
||||
isPathAbsolute: function(env, filename) {
|
||||
return /^(?:[a-z-]+:|\/|\\)/.test(filename);
|
||||
return (/^(?:[a-z-]+:|\/|\\)/).test(filename);
|
||||
},
|
||||
alwaysMakePathsAbsolute: function alwaysMakePathsAbsolute() {
|
||||
return false;
|
||||
},
|
||||
join: function join(basePath, laterPath) {
|
||||
if (!basePath) {
|
||||
return laterPath;
|
||||
}
|
||||
return basePath + laterPath;
|
||||
},
|
||||
pathDiff: function pathDiff(url, baseUrl) {
|
||||
// diff between two paths to create a relative path
|
||||
|
||||
var urlParts = this.extractUrlParts(url),
|
||||
baseUrlParts = this.extractUrlParts(baseUrl),
|
||||
i, max, urlDirectories, baseUrlDirectories, diff = "";
|
||||
if (urlParts.hostPart !== baseUrlParts.hostPart) {
|
||||
return "";
|
||||
}
|
||||
max = Math.max(baseUrlParts.directories.length, urlParts.directories.length);
|
||||
for(i = 0; i < max; i++) {
|
||||
if (baseUrlParts.directories[i] !== urlParts.directories[i]) { break; }
|
||||
}
|
||||
baseUrlDirectories = baseUrlParts.directories.slice(i);
|
||||
urlDirectories = urlParts.directories.slice(i);
|
||||
for(i = 0; i < baseUrlDirectories.length-1; i++) {
|
||||
diff += "../";
|
||||
}
|
||||
for(i = 0; i < urlDirectories.length-1; i++) {
|
||||
diff += urlDirectories[i] + "/";
|
||||
}
|
||||
return diff;
|
||||
},
|
||||
// helper function, not part of API
|
||||
extractUrlParts: function extractUrlParts(url, baseUrl) {
|
||||
// urlParts[1] = protocol&hostname || /
|
||||
// urlParts[2] = / if path relative to host base
|
||||
// urlParts[3] = directories
|
||||
// urlParts[4] = filename
|
||||
// urlParts[5] = parameters
|
||||
|
||||
var urlPartsRegex = /^((?:[a-z-]+:)?\/+?(?:[^\/\?#]*\/)|([\/\\]))?((?:[^\/\\\?#]*[\/\\])*)([^\/\\\?#]*)([#\?].*)?$/i,
|
||||
urlParts = url.match(urlPartsRegex),
|
||||
returner = {}, directories = [], i, baseUrlParts;
|
||||
|
||||
if (!urlParts) {
|
||||
throw new Error("Could not parse sheet href - '"+url+"'");
|
||||
}
|
||||
|
||||
// Stylesheets in IE don't always return the full path
|
||||
if (baseUrl && (!urlParts[1] || urlParts[2])) {
|
||||
baseUrlParts = baseUrl.match(urlPartsRegex);
|
||||
if (!baseUrlParts) {
|
||||
throw new Error("Could not parse page url - '"+baseUrl+"'");
|
||||
}
|
||||
urlParts[1] = urlParts[1] || baseUrlParts[1] || "";
|
||||
if (!urlParts[2]) {
|
||||
urlParts[3] = baseUrlParts[3] + urlParts[3];
|
||||
}
|
||||
}
|
||||
|
||||
if (urlParts[3]) {
|
||||
directories = urlParts[3].replace(/\\/g, "/").split("/");
|
||||
|
||||
// extract out . before .. so .. doesn't absorb a non-directory
|
||||
for(i = 0; i < directories.length; i++) {
|
||||
if (directories[i] === ".") {
|
||||
directories.splice(i, 1);
|
||||
i -= 1;
|
||||
}
|
||||
}
|
||||
|
||||
for(i = 0; i < directories.length; i++) {
|
||||
if (directories[i] === ".." && i > 0) {
|
||||
directories.splice(i-1, 2);
|
||||
i -= 2;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
returner.hostPart = urlParts[1];
|
||||
returner.directories = directories;
|
||||
returner.path = urlParts[1] + directories.join("/");
|
||||
returner.fileUrl = returner.path + (urlParts[4] || "");
|
||||
returner.url = returner.fileUrl + (urlParts[5] || "");
|
||||
return returner;
|
||||
},
|
||||
loadFile: function(env, filename, currentDirectory, callback) {
|
||||
var fullFilename,
|
||||
|
||||
@@ -103,11 +103,13 @@ less.Parser = function Parser(env) {
|
||||
// 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);
|
||||
if(newFileInfo.relativeUrls) {
|
||||
newFileInfo.rootpath = less.Parser.environment.join((env.rootpath || ""), less.Parser.environment.pathDiff(newFileInfo.currentDirectory, newFileInfo.entryPath));
|
||||
if (!less.Parser.environment.isPathAbsolute(env, newFileInfo.rootpath) && less.Parser.environment.alwaysMakePathsAbsolute()) {
|
||||
newFileInfo.rootpath = less.Parser.environment.join(newFileInfo.entryPath, newFileInfo.rootpath);
|
||||
}
|
||||
}
|
||||
newFileInfo.filename = resolvedFilename;
|
||||
|
||||
var newEnv = new tree.parseEnv(env);
|
||||
|
||||
Reference in New Issue
Block a user