import interpolation finished. refactored the import phase to occur only within the import visitor - so that the import eval env can be passed between imports.

This commit is contained in:
Luke Page
2013-03-01 13:06:34 +00:00
parent 14cee5d04f
commit 5d54af2039
21 changed files with 216 additions and 135 deletions

View File

@@ -249,26 +249,32 @@ function loadStyleSheet(sheet, callback, reload, remaining) {
var timestamp = cache && cache.getItem(href + ':timestamp');
var styles = { css: css, timestamp: timestamp };
var env;
var newFileInfo = {
relativeUrls: less.relativeUrls,
currentDirectory: hrefParts.path,
filename: href
};
if (sheet instanceof less.tree.parseEnv) {
env = new less.tree.parseEnv(sheet);
newFileInfo.entryPath = env.currentFileInfo.entryPath;
newFileInfo.rootpath = env.currentFileInfo.rootpath;
newFileInfo.rootFilename = env.currentFileInfo.rootFilename;
} else {
env = new less.tree.parseEnv(less);
env.entryPath = hrefParts.path;
env.mime = sheet.type;
newFileInfo.entryPath = hrefParts.path;
newFileInfo.rootpath = less.rootpath || hrefParts.path;
newFileInfo.rootFilename = href;
}
if (env.relativeUrls) {
//todo - this relies on option being set on less object rather than being passed in as an option
// - need an originalRootpath
if (less.rootpath) {
env.rootpath = extractUrlParts(less.rootpath + pathDiff(hrefParts.path, env.entryPath)).path;
newFileInfo.rootpath = extractUrlParts(less.rootpath + pathDiff(hrefParts.path, newFileInfo.entryPath)).path;
} else {
env.rootpath = hrefParts.path;
}
} else {
if (!less.rootpath) {
env.rootpath = env.entryPath;
newFileInfo.rootpath = hrefParts.path;
}
}
@@ -287,8 +293,8 @@ function loadStyleSheet(sheet, callback, reload, remaining) {
try {
env.contents[href] = data; // Updating content cache
env.paths = [hrefParts.path];
env.filename = href;
env.rootFilename = env.rootFilename || href;
env.currentFileInfo = newFileInfo;
new(less.Parser)(env).parse(data, function (e, root) {
if (e) { return callback(e, null, null, sheet); }
try {
@@ -296,7 +302,7 @@ function loadStyleSheet(sheet, callback, reload, remaining) {
//TODO - there must be a better way? A generic less-to-css function that can both call error
//and removeNode where appropriate
//should also add tests
if (env.rootFilename === href) {
if (env.currentFileInfo.rootFilename === href) {
removeNode(document.getElementById('less-error-message:' + extractId(href)));
}
} catch (e) {