Skip to content

Commit

Permalink
Fix for less.js issue #592, it is applied and compiled pull request
Browse files Browse the repository at this point in the history
  • Loading branch information
pogo19 committed Apr 27, 2012
1 parent 8dd18d1 commit 41dd17f
Showing 1 changed file with 24 additions and 14 deletions.
38 changes: 24 additions & 14 deletions src/main/resources/uk/org/cezary/t5conduit/less-1.3.0.js
Expand Up @@ -206,15 +206,20 @@ less.Parser = function Parser(env) {


var that = this; 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 // This function is called after all files
// have been imported through `@import`. // have been imported through `@import`.
var finish = function () {}; var finish = function () {};


var imports = this.imports = { var imports = this.imports = {
paths: env && env.paths || [], // Search paths, when importing paths: env && env.paths || [], // Search paths, when importing
queue: [], // Files which haven't been imported yet queue: [], // Files which haven't been imported yet
files: {}, // Holds the imported parse trees // files: {}, // Holds the imported parse trees - TODO: Not used, REMOVE?
contents: {}, // Holds the imported file contents contents: env.contents, // Holds the imported file contents
mime: env && env.mime, // MIME type of .less files mime: env && env.mime, // MIME type of .less files
error: null, // Error in parsing/evaluating an import error: null, // Error in parsing/evaluating an import
push: function (path, callback) { push: function (path, callback) {
Expand All @@ -224,10 +229,10 @@ less.Parser = function Parser(env) {
// //
// Import a file asynchronously // Import a file asynchronously
// //
// TODO: Remove "contents" argument?
less.Parser.importer(path, this.paths, function (e, root, contents) { 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.queue.splice(that.queue.indexOf(path), 1); // Remove the path from the queue
that.files[path] = root; // Store the root // that.files[path] = root; // Store the root - TODO: Not used, REMOVE?
that.contents[path] = contents;


if (e && !that.error) { that.error = e } if (e && !that.error) { that.error = e }
callback(e, root); callback(e, root);
Expand Down Expand Up @@ -332,17 +337,18 @@ less.Parser = function Parser(env) {
} }
} }


function basename(pathname) { // TODO: Removing this - Using basename() here can mess the cache due to name clashes across the import tree!!!
if (less.mode === 'node') { // function basename(pathname) {
return require('path').basename(pathname); // if (less.mode === 'node') {
} else { // return require('path').basename(pathname);
return pathname.match(/[^\/]+$/)[0]; // } else {
} // return pathname.match(/[^\/]+$/)[0];
} // }
// }


function getInput(e, env) { function getInput(e, env) {
if (e.filename && env.filename && (e.filename !== env.filename)) { if (e.filename && env.filename && (e.filename !== env.filename)) {
return parser.imports.contents[basename(e.filename)]; return parser.imports.contents[e.filename];
} else { } else {
return input; return input;
} }
Expand Down Expand Up @@ -1434,7 +1440,8 @@ if (less.mode === 'browser' || less.mode === 'rhino') {
// We pass `true` as 3rd argument, to force the reload of the import. // 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, // 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. // 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") { if (e && typeof(env.errback) === "function") {
env.errback.call(null, path, paths, callback, env); env.errback.call(null, path, paths, callback, env);
} else { } else {
Expand Down Expand Up @@ -3218,6 +3225,7 @@ function loadStyleSheets(callback, reload) {
} }


function loadStyleSheet(sheet, callback, reload, remaining) { 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 url = window.location.href.replace(/[#?].*$/, '');
var href = sheet.href.replace(/\?.*$/, ''); var href = sheet.href.replace(/\?.*$/, '');
var css = cache && cache.getItem(href); var css = cache && cache.getItem(href);
Expand All @@ -3244,11 +3252,13 @@ function loadStyleSheet(sheet, callback, reload, remaining) {
} else { } else {
// Use remote copy (re-parse) // Use remote copy (re-parse)
try { try {
contents[filename] = data; // Updating top importing parser content cache
new(less.Parser)({ new(less.Parser)({
optimization: less.optimization, optimization: less.optimization,
paths: [href.replace(/[\w\.-]+$/, '')], paths: [href.replace(/[\w\.-]+$/, '')],
mime: sheet.type, mime: sheet.type,
filename: filename filename: filename,
'contents': contents // Passing top importing parser content cache ref down.
}).parse(data, function (e, root) { }).parse(data, function (e, root) {
if (e) { return error(e, href) } if (e) { return error(e, href) }
try { try {
Expand Down

0 comments on commit 41dd17f

Please sign in to comment.