5 // The general strategy here is that we don't want to wait
6 // for the parsing to be completed, before we start importing
7 // the file. That's because in the context of a browser,
8 // most of the time will be spent waiting for the server to respond.
10 // On creation, we push the import path to our import queue, though
11 // `import,push`, we also pass it a callback, which it'll call once
12 // the file has been fetched, and parsed.
14 tree.Import = function (path, imports) {
19 // The '.less' extension is optional
20 if (path instanceof tree.Quoted) {
21 this.path = /\.(le?|c)ss(\?.*)?$/.test(path.value) ? path.value : path.value + '.less';
23 this.path = path.value.value || path.value;
26 this.css = /css(\?.*)?$/.test(this.path);
28 // Only pre-compile .less files
30 imports.push(this.path, function (root) {
32 throw new(Error)("Error parsing " + that.path);
40 // The actual import node doesn't return anything, when converted to CSS.
41 // The reason is that it's used at the evaluation stage, so that the rules
42 // it imports can be treated like any other rules.
44 // In `eval`, we make sure all Import nodes get evaluated, recursively, so
45 // we end up with a flat structure, which can easily be imported in the parent
48 tree.Import.prototype = {
51 return "@import " + this._path.toCSS() + ';\n';
56 eval: function (env) {
62 ruleset = new(tree.Ruleset)(null, this.root.rules.slice(0));
64 for (var i = 0; i < ruleset.rules.length; i++) {
65 if (ruleset.rules[i] instanceof tree.Import) {
69 [i, 1].concat(ruleset.rules[i].eval(env)));
77 })(require('less/tree'));