Skip to content

Commit

Permalink
Fix the rest of import silent
Browse files Browse the repository at this point in the history
  • Loading branch information
lukeapage committed Apr 30, 2013
1 parent 028de98 commit cc6c85a
Show file tree
Hide file tree
Showing 7 changed files with 65 additions and 14 deletions.
7 changes: 5 additions & 2 deletions lib/less/tree/comment.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,12 @@ tree.Comment = function (value, silent, index, currentFileInfo) {
tree.Comment.prototype = {
type: "Comment",
toCSS: function (env) {
return (env.compress || (this.currentFileInfo && this.currentFileInfo.silent)) ? '' : this.value;
return (env.compress || (this.currentFileInfo && this.currentFileInfo.silent && !this.isNotSilent)) ? '' : this.value;
},
eval: function () { return this; }
eval: function () { return this; },
markNotSilent: function () {
this.isNotSilent = true;
}
};

})(require('../tree'));
16 changes: 14 additions & 2 deletions lib/less/tree/directive.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ tree.Directive.prototype = {
},
toCSS: function (env) {

if (this.currentFileInfo.silent) {
if (this.currentFileInfo.silent && !this.isNotSilent) {
return "";
}

Expand All @@ -44,7 +44,19 @@ tree.Directive.prototype = {
},
variable: function (name) { return tree.Ruleset.prototype.variable.call(this.ruleset, name) },
find: function () { return tree.Ruleset.prototype.find.apply(this.ruleset, arguments) },
rulesets: function () { return tree.Ruleset.prototype.rulesets.apply(this.ruleset) }
rulesets: function () { return tree.Ruleset.prototype.rulesets.apply(this.ruleset) },
markNotSilent: function () {
var rule, i;
this.isNotSilent = true;
if (this.ruleset) {
for (i = 0; i < this.ruleset.rules.length; i++) {
rule = this.ruleset.rules[i];
if (rule.markNotSilent) {
rule.markNotSilent();
}
}
}
}
};

})(require('../tree'));
10 changes: 10 additions & 0 deletions lib/less/tree/media.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,16 @@ tree.Media.prototype = {
var el = new(tree.Element)('', '&', 0);
return [new(tree.Selector)([el], null, this.index, this.currentFileInfo)];
},
markNotSilent: function () {
var rule, i;
this.isNotSilent = true;
for (i = 0; i < this.ruleset.rules.length; i++) {
rule = this.ruleset.rules[i];
if (rule.markNotSilent) {
rule.markNotSilent();
}
}
},

evalTop: function (env) {
var result = this;
Expand Down
10 changes: 7 additions & 3 deletions lib/less/tree/mixin.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ tree.mixin.Call.prototype = {
this.arguments = visitor.visit(this.arguments);
},
eval: function (env) {
var mixins, mixin, args, rules = [], match = false, i, m, f, isRecursive, isOneFound;
var mixins, mixin, args, rules = [], match = false, i, m, f, isRecursive, isOneFound, rule;

args = this.arguments && this.arguments.map(function (a) {
return { name: a.name, value: a.value.eval(env) };
Expand Down Expand Up @@ -50,8 +50,12 @@ tree.mixin.Call.prototype = {
}
if (match) {
if (!this.currentFileInfo || !this.currentFileInfo.silent) {
//todo tell the rules that they are not silent
// make sure the rules pass that information when eval'd
for (i = 0; i < rules.length; i++) {
rule = rules[i];
if (rule.markNotSilent) {
rule.markNotSilent();
}
}
}
return rules;
}
Expand Down
6 changes: 6 additions & 0 deletions lib/less/tree/ruleset.js
Original file line number Diff line number Diff line change
Expand Up @@ -278,6 +278,12 @@ tree.Ruleset.prototype = {
return css.join('') + (env.compress ? '\n' : '');
},

markNotSilent: function () {
for (var s = 0; s < this.selectors.length; s++) {
this.selectors[s].markNotSilent();
}
},

joinSelectors: function (paths, context, selectors) {
for (var s = 0; s < selectors.length; s++) {
this.joinSelector(paths, context, selectors[s]);
Expand Down
18 changes: 11 additions & 7 deletions lib/less/tree/selector.js
Original file line number Diff line number Diff line change
@@ -1,18 +1,19 @@
(function (tree) {

tree.Selector = function (elements, extendList, index, currentFileInfo) {
tree.Selector = function (elements, extendList, index, currentFileInfo, isNotSilent) {
this.elements = elements;
this.extendList = extendList || [];
this.currentFileInfo = currentFileInfo || {}; // TODO remove
this.currentFileInfo = currentFileInfo || {};
this.isNotSilent = isNotSilent;
};
tree.Selector.prototype = {
type: "Selector",
accept: function (visitor) {
this.elements = visitor.visit(this.elements);
this.extendList = visitor.visit(this.extendList)
},
createDerived: function(elements) {
return new(tree.Selector)(elements, this.extendList, this.index, this.currentFileInfo);
createDerived: function(elements, extendList) {
return new(tree.Selector)(elements, extendList || this.extendList, this.index, this.currentFileInfo, this.isNotSilent);
},
match: function (other) {
var elements = this.elements,
Expand All @@ -36,11 +37,11 @@ tree.Selector.prototype = {
return true;
},
eval: function (env) {
return new(tree.Selector)(this.elements.map(function (e) {
return this.createDerived(this.elements.map(function (e) {
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 }
Expand All @@ -61,8 +62,11 @@ tree.Selector.prototype = {

return this._css;
},
markNotSilent: function () {
this.isNotSilent = true;
},
isSilent: function() {
return this.currentFileInfo.silent;
return this.currentFileInfo.silent && !this.isNotSilent;
}
};

Expand Down
12 changes: 12 additions & 0 deletions test/css/import-silent.css
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,18 @@
.b .c {
color: green;
}
.b:hover {
color: green;
}
.b {
color: green;
}
.b + .b {
color: green;
}
.b + .b .sub {
color: green;
}
.y {
pulled-in: yes;
}
Expand Down

0 comments on commit cc6c85a

Please sign in to comment.