Skip to content
Browse files

Fix for less.js issue #592, it is applied and compiled pull request

  • Loading branch information...
1 parent 8dd18d1 commit 41dd17f065f7b464a6983248d36c335359fd60ef @pogo19 committed Apr 27, 2012
Showing with 24 additions and 14 deletions.
  1. +24 −14 src/main/resources/uk/org/cezary/t5conduit/less-1.3.0.js
View
38 src/main/resources/uk/org/cezary/t5conduit/less-1.3.0.js
@@ -206,15 +206,20 @@ less.Parser = function Parser(env) {
var that = this;
+ // Top parser on an import tree must be sure there is one "env"
+ // which will then be passed arround by reference.
+ var env = env || { };
+ if (!env.contents) { env.contents={}; } // env.contents must be passed arround with top env
+
// This function is called after all files
// have been imported through `@import`.
var finish = function () {};
var imports = this.imports = {
paths: env && env.paths || [], // Search paths, when importing
queue: [], // Files which haven't been imported yet
- files: {}, // Holds the imported parse trees
- contents: {}, // Holds the imported file contents
+// files: {}, // Holds the imported parse trees - TODO: Not used, REMOVE?
+ contents: env.contents, // Holds the imported file contents
mime: env && env.mime, // MIME type of .less files
error: null, // Error in parsing/evaluating an import
push: function (path, callback) {
@@ -224,10 +229,10 @@ less.Parser = function Parser(env) {
//
// Import a file asynchronously
//
+ // TODO: Remove "contents" argument?
less.Parser.importer(path, this.paths, function (e, root, contents) {
that.queue.splice(that.queue.indexOf(path), 1); // Remove the path from the queue
- that.files[path] = root; // Store the root
- that.contents[path] = contents;
+// that.files[path] = root; // Store the root - TODO: Not used, REMOVE?
if (e && !that.error) { that.error = e }
callback(e, root);
@@ -332,17 +337,18 @@ less.Parser = function Parser(env) {
}
}
- function basename(pathname) {
- if (less.mode === 'node') {
- return require('path').basename(pathname);
- } else {
- return pathname.match(/[^\/]+$/)[0];
- }
- }
+// TODO: Removing this - Using basename() here can mess the cache due to name clashes across the import tree!!!
+// function basename(pathname) {
+// if (less.mode === 'node') {
+// return require('path').basename(pathname);
+// } else {
+// return pathname.match(/[^\/]+$/)[0];
+// }
+// }
function getInput(e, env) {
if (e.filename && env.filename && (e.filename !== env.filename)) {
- return parser.imports.contents[basename(e.filename)];
+ return parser.imports.contents[e.filename];
} else {
return input;
}
@@ -1434,7 +1440,8 @@ if (less.mode === 'browser' || less.mode === 'rhino') {
// 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.
- loadStyleSheet({ href: path, title: path, type: env.mime }, function (e) {
+ // __ Now using the hack of passing a ref to top parser's content cache in the 1st arg. __
+ loadStyleSheet({ href: path, title: path, type: env.mime, contents: env.contents }, function (e) {
if (e && typeof(env.errback) === "function") {
env.errback.call(null, path, paths, callback, env);
} else {
@@ -3218,6 +3225,7 @@ function loadStyleSheets(callback, reload) {
}
function loadStyleSheet(sheet, callback, reload, remaining) {
+ var contents = sheet.contents || {}; // Passing a ref to top importing parser content cache trough 'sheet' arg.
var url = window.location.href.replace(/[#?].*$/, '');
var href = sheet.href.replace(/\?.*$/, '');
var css = cache && cache.getItem(href);
@@ -3244,11 +3252,13 @@ function loadStyleSheet(sheet, callback, reload, remaining) {
} else {
// Use remote copy (re-parse)
try {
+ contents[filename] = data; // Updating top importing parser content cache
new(less.Parser)({
optimization: less.optimization,
paths: [href.replace(/[\w\.-]+$/, '')],
mime: sheet.type,
- filename: filename
+ filename: filename,
+ 'contents': contents // Passing top importing parser content cache ref down.
}).parse(data, function (e, root) {
if (e) { return error(e, href) }
try {

0 comments on commit 41dd17f

Please sign in to comment.
Something went wrong with that request. Please try again.