diff --git a/lib/less/import-visitor.js b/lib/less/import-visitor.js index 3f58d980..462290c3 100644 --- a/lib/less/import-visitor.js +++ b/lib/less/import-visitor.js @@ -1,12 +1,20 @@ (function (tree) { - tree.importVisitor = function(root) { + tree.importVisitor = function(root, importer) { this._visitor = new tree.visitor(this); + this._importer = importer; this._visitor.visit(root); }; tree.importVisitor.prototype = { visitImport: function (importNode, visitArgs) { - + if (!importNode.css) { + this._importer.push(importNode.path, function (e, root, imported) { + if (e) { e.index = importNode.index; } + if (imported && importNode.once) { importNode.skip = imported; } + importNode.root = root || new(tree.Ruleset)([], []); + }); + } + visitArgs.visitDeeper = false; return importNode; }, visitRule: function (ruleNode, visitArgs) { diff --git a/lib/less/parser.js b/lib/less/parser.js index 14f063fc..9eb8b66f 100644 --- a/lib/less/parser.js +++ b/lib/less/parser.js @@ -468,7 +468,7 @@ less.Parser = function Parser(env) { }; } - new tree.importVisitor(root); + new tree.importVisitor(root, parser.imports); finish = function (e) { e = error || e || parser.imports.error; @@ -1215,7 +1215,7 @@ less.Parser = function Parser(env) { if ($(';')) { features = features && new(tree.Value)(features); var importOnce = dir[1] !== 'multiple'; - return new(tree.Import)(path, imports, features, importOnce, index, env.rootpath); + return new(tree.Import)(path, features, importOnce, index, env.rootpath); } } diff --git a/lib/less/tree/import.js b/lib/less/tree/import.js index 01794bd9..bf1ee7eb 100644 --- a/lib/less/tree/import.js +++ b/lib/less/tree/import.js @@ -11,7 +11,7 @@ // `import,push`, we also pass it a callback, which it'll call once // the file has been fetched, and parsed. // -tree.Import = function (path, imports, features, once, index, rootpath) { +tree.Import = function (path, features, once, index, rootpath) { var that = this; this.once = once; @@ -28,15 +28,6 @@ tree.Import = function (path, imports, features, once, index, rootpath) { } this.css = /css([\?;].*)?$/.test(this.path); - - // Only pre-compile .less files - if (! this.css) { - imports.push(this.path, function (e, root, imported) { - if (e) { e.index = index; } - if (imported && that.once) { that.skip = imported; } - that.root = root || new(tree.Ruleset)([], []); - }); - } }; // @@ -73,7 +64,7 @@ tree.Import.prototype = { if (this.skip) { return []; } if (this.css) { - return new(tree.Import)(this._path, null, features, this.once, this.index, this.rootpath); + return new(tree.Import)(this._path, features, this.once, this.index, this.rootpath); } else { ruleset = new(tree.Ruleset)([], this.root.rules.slice(0)); diff --git a/lib/less/visitor.js b/lib/less/visitor.js index 634badf6..ed0f2c95 100644 --- a/lib/less/visitor.js +++ b/lib/less/visitor.js @@ -20,7 +20,7 @@ visitArgs; if (func) { visitArgs = {visitDeeper: true}; - node = func(node, visitArgs); + node = func.call(this._implementation, node, visitArgs); } if ((!visitArgs || visitArgs.visitDeeper) && node && node.accept) { node.accept(this);