Skip to content

Commit e63c8c5

Browse files
committed
Move importing into visitor
1 parent 39f669e commit e63c8c5

File tree

4 files changed

+15
-16
lines changed

4 files changed

+15
-16
lines changed

lib/less/import-visitor.js

+10-2
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,20 @@
11
(function (tree) {
2-
tree.importVisitor = function(root) {
2+
tree.importVisitor = function(root, importer) {
33
this._visitor = new tree.visitor(this);
4+
this._importer = importer;
45
this._visitor.visit(root);
56
};
67

78
tree.importVisitor.prototype = {
89
visitImport: function (importNode, visitArgs) {
9-
10+
if (!importNode.css) {
11+
this._importer.push(importNode.path, function (e, root, imported) {
12+
if (e) { e.index = importNode.index; }
13+
if (imported && importNode.once) { importNode.skip = imported; }
14+
importNode.root = root || new(tree.Ruleset)([], []);
15+
});
16+
}
17+
visitArgs.visitDeeper = false;
1018
return importNode;
1119
},
1220
visitRule: function (ruleNode, visitArgs) {

lib/less/parser.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -468,7 +468,7 @@ less.Parser = function Parser(env) {
468468
};
469469
}
470470

471-
new tree.importVisitor(root);
471+
new tree.importVisitor(root, parser.imports);
472472

473473
finish = function (e) {
474474
e = error || e || parser.imports.error;
@@ -1215,7 +1215,7 @@ less.Parser = function Parser(env) {
12151215
if ($(';')) {
12161216
features = features && new(tree.Value)(features);
12171217
var importOnce = dir[1] !== 'multiple';
1218-
return new(tree.Import)(path, imports, features, importOnce, index, env.rootpath);
1218+
return new(tree.Import)(path, features, importOnce, index, env.rootpath);
12191219
}
12201220
}
12211221

lib/less/tree/import.js

+2-11
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
// `import,push`, we also pass it a callback, which it'll call once
1212
// the file has been fetched, and parsed.
1313
//
14-
tree.Import = function (path, imports, features, once, index, rootpath) {
14+
tree.Import = function (path, features, once, index, rootpath) {
1515
var that = this;
1616

1717
this.once = once;
@@ -28,15 +28,6 @@ tree.Import = function (path, imports, features, once, index, rootpath) {
2828
}
2929

3030
this.css = /css([\?;].*)?$/.test(this.path);
31-
32-
// Only pre-compile .less files
33-
if (! this.css) {
34-
imports.push(this.path, function (e, root, imported) {
35-
if (e) { e.index = index; }
36-
if (imported && that.once) { that.skip = imported; }
37-
that.root = root || new(tree.Ruleset)([], []);
38-
});
39-
}
4031
};
4132

4233
//
@@ -73,7 +64,7 @@ tree.Import.prototype = {
7364
if (this.skip) { return []; }
7465

7566
if (this.css) {
76-
return new(tree.Import)(this._path, null, features, this.once, this.index, this.rootpath);
67+
return new(tree.Import)(this._path, features, this.once, this.index, this.rootpath);
7768
} else {
7869
ruleset = new(tree.Ruleset)([], this.root.rules.slice(0));
7970

lib/less/visitor.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
visitArgs;
2121
if (func) {
2222
visitArgs = {visitDeeper: true};
23-
node = func(node, visitArgs);
23+
node = func.call(this._implementation, node, visitArgs);
2424
}
2525
if ((!visitArgs || visitArgs.visitDeeper) && node && node.accept) {
2626
node.accept(this);

0 commit comments

Comments
 (0)