diff --git a/lib/less/browser.js b/lib/less/browser.js index 36b3bfbd..168a1e9b 100644 --- a/lib/less/browser.js +++ b/lib/less/browser.js @@ -248,7 +248,12 @@ function extractUrlParts(url, baseUrl) { } function loadStyleSheet(sheet, callback, reload, remaining) { - loadFile(sheet, function(e, data, sheet, webInfo, path, env) { + + var env = new less.tree.parseEnv(less); + env.mime = sheet.type; + env.currentFileInfo = null; + + loadFile(sheet, env, function(e, data, sheet, webInfo, path, env) { if (webInfo) { webInfo.remaining = remaining; } @@ -268,7 +273,7 @@ function loadStyleSheet(sheet, callback, reload, remaining) { }, reload); } -function loadFile(sheet, callback, reload) { +function loadFile(sheet, env, callback, reload) { // sheet may be set to the stylesheet for the initial load or a collection of properties including // some env variables for imports @@ -277,21 +282,18 @@ function loadFile(sheet, callback, reload) { var css = cache && cache.getItem(href); 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); + if (env.currentFileInfo) { + env = new less.tree.parseEnv(env); newFileInfo.entryPath = env.currentFileInfo.entryPath; newFileInfo.rootpath = env.currentFileInfo.rootpath; newFileInfo.rootFilename = env.currentFileInfo.rootFilename; } else { - env = new less.tree.parseEnv(less); - env.mime = sheet.type; newFileInfo.entryPath = hrefParts.path; newFileInfo.rootpath = less.rootpath || hrefParts.path; newFileInfo.rootFilename = href; diff --git a/lib/less/env.js b/lib/less/env.js index 91b0027e..6d46f393 100644 --- a/lib/less/env.js +++ b/lib/less/env.js @@ -46,14 +46,6 @@ } }; - tree.parseEnv.prototype.toSheet = function (path) { - var env = new tree.parseEnv(this); - env.href = path; - //env.title = path; - env.type = this.mime; - return env; - }; - var evalCopyProperties = [ 'silent', // whether to swallow errors and warnings 'verbose', // whether to log more activity diff --git a/lib/less/index.js b/lib/less/index.js index fa598d93..0207f4c1 100644 --- a/lib/less/index.js +++ b/lib/less/index.js @@ -113,8 +113,7 @@ less.Parser.fileLoader = function (file, currentFileInfo, callback, env) { function handleDataAndCallCallback(data) { env = new less.tree.parseEnv(env); - env.processImports = false; - + var j = file.lastIndexOf('/'); // Pass on an updated rootpath if path of imported file is relative and file diff --git a/lib/less/parser.js b/lib/less/parser.js index c06a914a..f3c5e186 100644 --- a/lib/less/parser.js +++ b/lib/less/parser.js @@ -100,6 +100,8 @@ less.Parser = function Parser(env) { less.Parser.fileLoader(path, currentFileInfo, function(e, contents, fullPath, env) { if (e) {fileParsedFunc(e); return;} + env.processImports = false; + new(less.Parser)(env).parse(contents, function (e, root) { fileParsedFunc(e, root, fullPath); }); @@ -1604,14 +1606,11 @@ if (less.mode === 'browser' || less.mode === 'rhino') { if (!/^([a-z-]+:)?\//.test(path) && currentFileInfo.currentDirectory) { path = currentFileInfo.currentDirectory + path; } - var sheetEnv = env.toSheet(path); - sheetEnv.processImports = false; - sheetEnv.currentFileInfo = currentFileInfo; // We pass `true` as 3rd argument, to force the reload of the import. // This is so we can get the syntax tree as opposed to just the CSS output, // as we need this to evaluate the current stylesheet. - loadFile(sheetEnv, + loadFile({href: path, type: env.mime }, env, function (e, data, sheet, webInfo, path, env) { callback(e, data, path, env); }, true);