mirror of
https://github.com/less/less.js.git
synced 2026-01-22 21:58:14 -05:00
Move importing into visitor
This commit is contained in:
@@ -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) {
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -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));
|
||||
|
||||
|
||||
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user