Basic functionality and basic tests for import silent

This commit is contained in:
Luke Page
2013-03-21 15:09:10 +00:00
parent 898e27f525
commit 5df82b69ce
6 changed files with 46 additions and 18 deletions

View File

@@ -1168,7 +1168,7 @@ less.Parser = function Parser(env) {
if (c === '{' || c === '}' || c === ';' || c === ',' || c === ')') { break }
}
if (elements.length > 0) { return new(tree.Selector)(elements, extendList); }
if (elements.length > 0) { return new(tree.Selector)(elements, extendList, i, env.currentFileInfo); }
if (extendList.length) { error("Extend must be used to extend a selector, it cannot be used on its own"); }
},
attribute: function () {

View File

@@ -241,24 +241,36 @@ tree.Ruleset.prototype = {
} else {
if (rules.length > 0) {
debugInfo = tree.debugInfo(env, this);
selector = this.paths.map(function (p) {
return p.map(function (s) {
return s.toCSS(env);
}).join('').trim();
}).join(env.compress ? ',' : ',\n');
selector = this.paths
.filter(function(p) {
var i;
for(i = 0; i < p.length; i++) {
if (!p[i].isSilent()) {
return true;
}
return false;
}
})
.map(function (p) {
return p.map(function (s) {
return s.toCSS(env);
}).join('').trim();
}).join(env.compress ? ',' : ',\n');
// Remove duplicates
for (var i = rules.length - 1; i >= 0; i--) {
if (rules[i].slice(0, 2) === "/*" || _rules.indexOf(rules[i]) === -1) {
_rules.unshift(rules[i]);
if (selector) {
// Remove duplicates
for (var i = rules.length - 1; i >= 0; i--) {
if (rules[i].slice(0, 2) === "/*" || _rules.indexOf(rules[i]) === -1) {
_rules.unshift(rules[i]);
}
}
}
rules = _rules;
rules = _rules;
css.push(debugInfo + selector +
(env.compress ? '{' : ' {\n ') +
rules.join(env.compress ? '' : '\n ') +
(env.compress ? '}' : '\n}\n'));
css.push(debugInfo + selector +
(env.compress ? '{' : ' {\n ') +
rules.join(env.compress ? '' : '\n ') +
(env.compress ? '}' : '\n}\n'));
}
}
}
css.push(rulesets);

View File

@@ -1,8 +1,9 @@
(function (tree) {
tree.Selector = function (elements, extendList) {
tree.Selector = function (elements, extendList, index, currentFileInfo) {
this.elements = elements;
this.extendList = extendList || [];
this.currentFileInfo = currentFileInfo || {}; // TODO remove
};
tree.Selector.prototype = {
type: "Selector",
@@ -36,7 +37,7 @@ tree.Selector.prototype = {
return e.eval(env);
}), this.extendList.map(function(extend) {
return extend.eval(env);
}));
}), this.index, this.currentFileInfo);
},
toCSS: function (env) {
if (this._css) { return this._css }
@@ -56,6 +57,9 @@ tree.Selector.prototype = {
}).join('');
return this._css;
},
isSilent: function() {
return this.currentFileInfo.silent;
}
};

View File

@@ -0,0 +1,3 @@
.b {
color: red;
}

View File

@@ -0,0 +1,6 @@
@import (silent) url("import-once.less");
@import (silent) url("import/import-silent.less");
.b {
.a();
}

View File

@@ -0,0 +1,3 @@
.a {
color: red;
}